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

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

  // foreign key to parent task
  taskId: uuid("task_id")
    .notNull()
    .references(() => tasks.id, { onDelete: "cascade" }),

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

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

  inputs: text("inputs"), // could later change to JSONB if desired
  outputs: text("outputs"),
  cloudLogsURL: text("cloud_logs_url"),

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