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

export const bulkAddressUploads = pgTable("bulk_address_uploads", {
  id: uuid("id").defaultRandom().primaryKey(),
  portfolioId: text("portfolio_id").notNull(),
  userId: text("user_id").notNull(),
  s3Bucket: text("s3_bucket").notNull(),
  s3Key: text("s3_key").notNull(),
  filename: text("filename").notNull(),
  status: text("status").notNull().default("ready_for_processing"),
  sourceHeaders: text("source_headers").array().notNull().default(sql`'{}'`),
  columnMapping: jsonb("column_mapping").$type<Record<string, string>>(),
  taskId: uuid("task_id"),
  combinedOutputS3Uri: text("combined_output_s3_uri"),
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
  updatedAt: timestamp("updated_at", { withTimezone: true })
    .notNull()
    .defaultNow()
    .$onUpdate(() => new Date()),
});
