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

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

export const letterheads = pgTable("letterheads", {
    id: bigint("id", { mode: "number" })
        .primaryKey()
        .generatedByDefaultAsIdentity(),

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

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

    name: text("name").default("Standard"),

    path: text("path").notNull(),

    documentTypes: text("documentTypes").array().notNull().default([]),

    updatedAt: timestamp("updated_at", { withTimezone: true }),
    updatedBy: uuid("updated_by").references(() => authUsers.id),

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

export type Letterhead = typeof letterheads.$inferSelect
export type NewLetterhead = typeof letterheads.$inferInsert
