import { pgTable, text, timestamp, index, integer } from "drizzle-orm/pg-core";
import { users } from "./users";

export const comments = pgTable(
  "comments",
  {
    id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
    collection: text("collection").notNull(), // 'videos' | 'recordings'
    item_id: text("item_id").notNull(),
    comment: text("comment").notNull(),
    user_id: text("user_id")
      .notNull()
      .references(() => users.id, { onDelete: "cascade" }),
    date_created: timestamp("date_created").notNull().defaultNow(),
    date_updated: timestamp("date_updated"),
  },
  (t) => [
    index("comments_collection_item_idx").on(t.collection, t.item_id),
    index("comments_user_idx").on(t.user_id),
  ],
);

export type Comment = typeof comments.$inferSelect;
export type NewComment = typeof comments.$inferInsert;
