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

export const sourceEnum = pgEnum("source", ["portfolio_id", "hubspot_deal_id", "property_id"]);

export const tasks = pgTable("tasks", {
  id: uuid("id").defaultRandom().primaryKey(),

  taskSource: text("task_source").notNull(),

  jobStarted: timestamp("job_started", { precision: 6, withTimezone: true }),
  jobCompleted: timestamp("job_completed", { precision: 6, withTimezone: true }),

  status: text("status").notNull().default("In Progress"), // default status

  service: text("service"), // e.g. plan, wchg etc

  source: sourceEnum("source"), // enum for task source type

  sourceId: text("source_id"), // identifier for the source (e.g., portfolio_id value)

  // The task's request inputs, mirroring sub_task.inputs (JSON as text; could
  // later change to JSONB). For a modelling run this is the run's config —
  // portfolio id, scenario ids, filters (ADR-0008).
  inputs: text("inputs"),

  updatedAt: timestamp("updated_at", { precision: 6, withTimezone: true })
    .defaultNow()
    .$onUpdate(() => new Date())
    .notNull(),
});
