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

export const textbooks = mysqlTable("content_textbooks", {
  id: char("id", { length: 36 }).notNull().primaryKey(),
  title: varchar("title", { length: 200 }).notNull(),
  subjectId: char("subject_id", { length: 36 }).notNull(),
  gradeId: char("grade_id", { length: 36 }).notNull(),
  version: varchar("version", { length: 50 }).notNull(),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  updatedAt: timestamp("updated_at").notNull().defaultNow().onUpdateNow(),
});

export const chapters = mysqlTable("content_chapters", {
  id: char("id", { length: 36 }).notNull().primaryKey(),
  textbookId: char("textbook_id", { length: 36 }).notNull(),
  title: varchar("title", { length: 200 }).notNull(),
  order: int("order_num").notNull(),
  parentId: char("parent_id", { length: 36 }),
});

export const knowledgePoints = mysqlTable("content_knowledge_points", {
  id: char("id", { length: 36 }).notNull().primaryKey(),
  chapterId: char("chapter_id", { length: 36 }).notNull(),
  title: varchar("title", { length: 200 }).notNull(),
  description: text("description"),
});

export type Textbook = typeof textbooks.$inferSelect;
export type NewTextbook = typeof textbooks.$inferInsert;
export type Chapter = typeof chapters.$inferSelect;
export type NewChapter = typeof chapters.$inferInsert;
export type KnowledgePoint = typeof knowledgePoints.$inferSelect;
export type NewKnowledgePoint = typeof knowledgePoints.$inferInsert;
