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

// ----- MOVIES (specific fields only) -----
export const movies = sqliteTable(
	"movies",
	{
		id: text("id")
			.primaryKey()
			.$defaultFn(() => {
				return Bun.randomUUIDv7();
			}),
		titleId: text("title_id")
			.notNull()
			.unique()
			.references(() => titles.id, { onDelete: "cascade" }),
		runtimeSeconds: integer("runtime_seconds"),
		createdAt: integer("created_at", { mode: "timestamp" })
			.$defaultFn(() => new Date())
			.notNull(),
		updatedAt: integer("updated_at", { mode: "timestamp" })
			.$defaultFn(() => new Date())
			.$onUpdate(() => new Date())
			.notNull(),
	},
	(t) => [index("idx_movies_title").on(t.titleId)],
);
