import { pgTable, uuid, timestamp, index } from "drizzle-orm/pg-core";
import { companies } from "./companies.js";
import { chatMessages } from "./chat_messages.js";
import { chatConversations } from "./chat_conversations.js";

export const chatMessageBookmarks = pgTable(
  "chat_message_bookmarks",
  {
    id: uuid("id").primaryKey().defaultRandom(),
    companyId: uuid("company_id").notNull().references(() => companies.id),
    messageId: uuid("message_id").notNull().references(() => chatMessages.id, { onDelete: "cascade" }),
    conversationId: uuid("conversation_id").notNull().references(() => chatConversations.id, { onDelete: "cascade" }),
    createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
  },
  (table) => ({
    companyMessageIdx: index("chat_bookmarks_company_message_idx").on(table.companyId, table.messageId),
    companyConvIdx: index("chat_bookmarks_company_conv_idx").on(table.companyId, table.conversationId),
  }),
);
