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

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

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

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

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

    initialPhases: jsonb("initialPhases"),
    addablePhases: jsonb("addablePhases"),

    icon: text("icon"),

    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 ProjectType = typeof projecttypes.$inferSelect
export type NewProjectType = typeof projecttypes.$inferInsert
