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

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

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

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

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

    type: text("type").notNull(),
    billingInterval: text("billingInterval").notNull(),
    billingAmount: doublePrecision("billingAmount").notNull().default(0),

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

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

export type MemberRelation = typeof memberrelations.$inferSelect
export type NewMemberRelation = typeof memberrelations.$inferInsert

