import type { ReportType, StageKey } from "./types";

/**
 * Outcome report order and labels (V2 `outcomes/reportTypes.ts`, master plan §20.2).
 * `after` = default days after class end when the report becomes due (configurable server-side).
 */
export const REPORT_ORDER: {
  type: ReportType;
  stageKey?: StageKey;
  label: string;
  after: number;
  prerequisite?: string;
  listed: string;
}[] = [
  {
    type: "dropout",
    label: "Dropout",
    after: 7,
    listed: "All tracked trainees (active + reserve)",
  },
  {
    type: "completion",
    label: "Completion",
    after: 21,
    prerequisite: "Dropout report accepted",
    listed: "All tracked trainees except dropouts",
  },
  {
    type: "certification",
    label: "Certification",
    after: 45,
    prerequisite: "Completion report accepted",
    listed: "Completers",
  },
  {
    type: "employment_placement",
    label: "Employment placement",
    after: 60,
    prerequisite: "Certification report accepted",
    listed: "Certified trainees",
  },
  {
    type: "locality_compliant",
    label: "Locality",
    after: 70,
    prerequisite: "Employment placement report accepted",
    listed: "Trainees in employment",
  },
  {
    type: "job_retention_3m",
    label: "Retention 3 m",
    after: 150,
    prerequisite: "Employment placement report accepted",
    listed: "Trainees in employment",
  },
];
export const reportKey = (type: ReportType, stageKey?: string) =>
  stageKey ? `${type}:${stageKey}` : type;
export const reportLabel = (type: ReportType, stageKey?: string) =>
  REPORT_ORDER.find((r) => r.type === type && (r.stageKey ?? "") === (stageKey ?? ""))?.label ??
  type;

/** Keys of the reports that must be accepted before this one (same order as `prerequisite` above). */
export const reportPrerequisite = (type: ReportType, _stageKey?: string): string | undefined =>
  (
    ({
      completion: "dropout",
      certification: "completion",
      employment_placement: "certification",
      locality_compliant: "employment_placement",
      job_retention_3m: "employment_placement",
    }) as Record<string, string>
  )[type];

/** Dropout / non-completion reason codes (V2 enums). */
export const DROPOUT_REASONS = [
  ["voluntary_withdrawal", "Voluntary withdrawal"],
  ["dismissal", "Dismissal"],
  ["health", "Health"],
  ["economic", "Economic / financial"],
  ["migration", "Migration / relocation"],
  ["found_job", "Found a job"],
  ["low_attendance_auto", "Low attendance"],
  ["other", "Other"],
] as const;
export const NONCOMPLETION_REASONS = [
  ["failed_assessment", "Failed final assessment"],
  ["incomplete_assignments", "Incomplete assignments"],
  ["insufficient_attendance", "Insufficient attendance"],
  ["other", "Other"],
] as const;
