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

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

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

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

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

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

    infoData: jsonb("infoData").notNull().default({}),
    notes: text("notes"),

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

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

    defaultPaymentMethod: text("defaultPaymentMethod"),

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

export type Vendor = typeof vendors.$inferSelect
export type NewVendor = typeof vendors.$inferInsert
