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

import { tenants } from "./tenants"

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

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

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

    startDate: timestamp("start_date", { withTimezone: true }).notNull(),
    endDate: timestamp("end_date", { withTimezone: true }).notNull(),

    validUntil: timestamp("valid_until", { withTimezone: true }),

    type: text("type").notNull().default("datev"),

    url: text("url").notNull(),
    filePath: text("file_path"),
})

export type Export = typeof generatedexports.$inferSelect
export type NewExport = typeof generatedexports.$inferInsert
