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

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

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

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

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

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

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

    description: text("description"),

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

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

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

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

export type InventoryItemGroup = typeof inventoryitemgroups.$inferSelect
export type NewInventoryItemGroup = typeof inventoryitemgroups.$inferInsert
