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

// 班级表（从 classes 服务合并，保留原表名兼容 CDC）
export const classes = mysqlTable(
  "classes",
  {
    id: char("id", { length: 36 }).notNull().primaryKey(),
    name: varchar("name", { length: 100 }).notNull(),
    gradeId: char("grade_id", { length: 36 }).notNull(),
    headTeacherId: char("head_teacher_id", { length: 36 }),
    description: text("description"),
    createdAt: timestamp("created_at").notNull().defaultNow(),
    updatedAt: timestamp("updated_at").notNull().defaultNow().onUpdateNow(),
  },
  (table) => ({
    idxClassesGradeId: index("idx_classes_grade_id").on(table.gradeId),
    idxClassesHeadTeacher: index("idx_classes_head_teacher").on(
      table.headTeacherId,
    ),
  }),
);

export type Class = typeof classes.$inferSelect;
export type NewClass = typeof classes.$inferInsert;
