import type { TaskStatus } from "@/lib/task-actions"

/**
 * The shape of one task as a screen reads it.
 *
 * Fields mirror `machine/task-fields.tsv` one for one, with one exception
 * called out below. The statuses come from `machine/lifecycle.json` and live in
 * `task-actions.ts`, because what a status permits is the interesting part.
 */

export type TaskEvent = { at: string; what: string; who: string }

/**
 * What the assignee handed in when they marked the task finished.
 *
 * PROTOTYPE. `machine/task-fields.tsv` has no field for this. It carries
 * `report_to_deliver` and `report_example_url`, which describe what was *asked
 * for*, and nothing at all for what *came back*. So a checker is handed Approve
 * and Send back with no trace of the work, and Approve becomes a reflex.
 *
 * The shape below is a proposal, not specification: a note in the assignee's
 * own words, the readings the task exists to capture, and the report as it was
 * actually delivered. Tracked in ELEVA-121; the specification folder is not
 * ours to edit, so nothing here is written back to `machine/`.
 */
export type TaskSubmission = {
  by: string
  at: string
  /** Free text, in the assignee's words. The one field that cannot be dropped. */
  note: string
  /** The numbers the task exists to capture, if it captures any. */
  readings?: { label: string; value: string }[]
  /** The report as delivered, against `report_to_deliver` which asked for it. */
  delivered?: { name: string; url: string; how: string }
}

export type Task = {
  description: string
  position: string
  department: string
  assignee: string
  occurrence: string
  due: Date | null
  status: TaskStatus
  checker: string
  verifier?: string
  minutes?: number
  reportToDeliver?: string
  reportExampleUrl?: string
  wiSopUrl?: string
  customerTag?: string
  oneTime?: boolean
  submission?: TaskSubmission
  history: TaskEvent[]
}

/** A badge holds a state. Whatever the state means is said where it applies. */
export const STATUS_WORD: Record<TaskStatus, string> = {
  todo: "To do",
  started: "Started",
  finished: "Finished",
  checked: "Complete",
  missed: "Missed",
}
