import {
    pgTable,
    uuid,
    timestamp,
    bigint,
    text,
    jsonb,
    boolean,
} from "drizzle-orm/pg-core"

import { tenants } from "./tenants"
import { customers } from "./customers"
import { vendors } from "./vendors"
import { authUsers } from "./auth_users"

export const createdletters = pgTable("createdletters", {
    id: uuid("id").primaryKey().defaultRandom(),

    createdAt: timestamp("created_at", { withTimezone: true })
        .notNull()
        .defaultNow(),

    tenant: bigint("tenant", { mode: "number" }).references(() => tenants.id),

    customer: bigint("customer", { mode: "number" }).references(
        () => customers.id
    ),

    vendor: bigint("vendor", { mode: "number" }).references(() => vendors.id),

    contentJson: jsonb("content_json").default([]),

    contentText: text("content_text"),

    updatedAt: timestamp("updated_at", { withTimezone: true }),

    updatedBy: uuid("updated_by").references(() => authUsers.id),

    archived: boolean("archived").notNull().default(false),
})

export type CreatedLetter = typeof createdletters.$inferSelect
export type NewCreatedLetter = typeof createdletters.$inferInsert
