import { pgTable, text, serial, timestamp, integer, boolean } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod/v4";

export const sessionRowsTable = pgTable("session_rows", {
  id: serial("id").primaryKey(),
  planId: integer("plan_id").notNull(),
  weekNumber: integer("week_number").notNull(),
  sessionNumber: integer("session_number").notNull(),
  topic: text("topic"),
  subtopic: text("subtopic"),
  learningOutcome: text("learning_outcome"),
  trainerActivity: text("trainer_activity"),
  traineeActivity: text("trainee_activity"),
  resources: text("resources"),
  assessmentMethod: text("assessment_method"),
  duration: text("duration"),
  performanceCriteria: text("performance_criteria"),
  evidenceRequired: text("evidence_required"),
  deliveryMode: text("delivery_mode"),
  practicalExercise: text("practical_exercise"),
  reflection: text("reflection"),
  notes: text("notes"),
  isLocked: boolean("is_locked").notNull().default(false),
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => new Date()),
});

export const insertSessionRowSchema = createInsertSchema(sessionRowsTable).omit({ id: true, createdAt: true, updatedAt: true });
export type InsertSessionRow = z.infer<typeof insertSessionRowSchema>;
export type SessionRow = typeof sessionRowsTable.$inferSelect;
