import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
import { projects } from "./projects";
import { characters } from "./characters";

export const scenes = sqliteTable("scenes", {
  id: integer("id").primaryKey({ autoIncrement: true }),
  projectId: integer("project_id")
    .notNull()
    .references(() => projects.id),
  title: text("title").notNull(),
  content: text("content").notNull().default(""),
  order: integer("order").notNull().default(0),
  createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
  updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
});

export const sceneCharacters = sqliteTable("scene_characters", {
  id: integer("id").primaryKey({ autoIncrement: true }),
  sceneId: integer("scene_id")
    .notNull()
    .references(() => scenes.id),
  characterId: integer("character_id")
    .notNull()
    .references(() => characters.id),
  screenTime: integer("screen_time"),
  dialogueLines: integer("dialogue_lines").default(0),
});

export type Scene = typeof scenes.$inferSelect;
export type NewScene = typeof scenes.$inferInsert;
export type SceneCharacter = typeof sceneCharacters.$inferSelect;
export type NewSceneCharacter = typeof sceneCharacters.$inferInsert;
