import { mysqlTable, varchar, text, timestamp, char, bigint } from 'drizzle-orm/mysql-core';

export const outbox = mysqlTable('core_edu_outbox', {
  id: char('id', { length: 36 }).notNull().primaryKey(),
  aggregateId: char('aggregate_id', { length: 36 }).notNull(),
  aggregateType: varchar('aggregate_type', { length: 50 }).notNull(),
  eventType: varchar('event_type', { length: 100 }).notNull(),
  payload: text('payload').notNull(),
  status: varchar('status', { length: 20 }).notNull().default('pending'),
  retryCount: bigint('retry_count', { mode: 'number' }).notNull().default(0),
  createdAt: timestamp('created_at').notNull().defaultNow(),
  processedAt: timestamp('processed_at'),
});

export type OutboxMessage = typeof outbox.$inferSelect;
export type NewOutboxMessage = typeof outbox.$inferInsert;
