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

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

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

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

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

    number: text("number").notNull(),
    name: text("name").notNull(),

    description: text("description"),

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

    profiles: jsonb("profiles").notNull().default([]),

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

export type OwnAccount = typeof ownaccounts.$inferSelect
export type NewOwnAccount = typeof ownaccounts.$inferInsert
