import {
    pgTable,
    uuid,
    text,
} from "drizzle-orm/pg-core"

import { helpdesk_conversations } from "./helpdesk_conversations"
import { authUsers } from "./auth_users"

export const helpdesk_conversation_participants = pgTable(
    "helpdesk_conversation_participants",
    {
        conversationId: uuid("conversation_id")
            .notNull()
            .references(() => helpdesk_conversations.id, { onDelete: "cascade" }),

        userId: uuid("user_id")
            .notNull()
            .references(() => authUsers.id, { onDelete: "cascade" }),

        role: text("role"),
    },
    (table) => ({
        pk: {
            name: "helpdesk_conversation_participants_pkey",
            columns: [table.conversationId, table.userId],
        },
    })
)

export type HelpdeskConversationParticipant =
    typeof helpdesk_conversation_participants.$inferSelect
export type NewHelpdeskConversationParticipant =
    typeof helpdesk_conversation_participants.$inferInsert
