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

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

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

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

    space: bigint("space", { mode: "number" }).references(() => spaces.id),

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

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

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

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

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

export type DocumentBox = typeof documentboxes.$inferSelect
export type NewDocumentBox = typeof documentboxes.$inferInsert
