/**
 * Measure Document Requirements
 * Maps HubSpot measure names to the required installer document types (fileType enum values).
 * Used to compute per-measure upload completion and guide contractors in the upload modal.
 */

/**
 * Canonical list of measure names recognised by the application.
 *
 * This is the single source of truth: document-requirement lookups, UI dropdowns
 * and validation should reference this tuple rather than maintaining their own
 * copies. Names match the values produced by the upstream HubSpot pull pipeline.
 */
export const MEASURE_NAMES = [
  "ASHP",
  "Solar PV",
  "DMevs",
  "Loft insulation",
  "CWI",
  "EWI",
  "IWI",
  "Flat roof",
  "RIR",
  "UFI",
  "HW",
  "Windows",
  "Ext. doors",
  "TRVs",
  "Heating controls",
  "New boiler",
  "HHRSH",
  "Battery",
  "LEL",
  "Listed building",
  "Removal 2nd heating",
  "Others",
] as const;

export type MeasureName = (typeof MEASURE_NAMES)[number];

// Required for every measure
const BASE_DOCS = [
  "pre_photo",
  "mid_photo",
  "post_photo",
  "pre_installation_building_inspection",
  "claim_of_compliance",
  "insurance_guarantee",
  "workmanship_warranty",
] as const;

// MCS-accredited measures require MCS certification in addition to base docs
const MCS_EXTRA = ["mcs_compliance_certificate"] as const;

export { BASE_DOCS };

export const MEASURE_DOC_REQUIREMENTS: Partial<Record<MeasureName, string[]>> = {
  ASHP: [...BASE_DOCS, ...MCS_EXTRA, "commissioning_records"],
  "Solar PV": [...BASE_DOCS, ...MCS_EXTRA, "g98_notification"],
  DMevs: [
    ...BASE_DOCS,
    "dmev_photos",
    "anemometer_readings",
    "commissioning_records",
    "part_f_ventilation_document",
    "door_undercut_photos",
    "trickle_vent_photos",
    "ventilation_assessment_checklist",
    "minor_works_electrical_certificate",
  ],
  "Loft insulation": [...BASE_DOCS, "loft_hatch_photo"],
  // All remaining measures require BASE_DOCS only:
  // CWI, EWI, IWI, "Flat roof", RIR, UFI, HW, Windows, "Ext. doors",
  // TRVs, "Heating controls", "New boiler", HHRSH, Battery, LEL,
  // "Listed building", "Removal 2nd heating", Others
};

/**
 * Returns the required document types for a given measure name.
 * Falls back to BASE_DOCS for any measure not explicitly listed (including
 * unknown measures from upstream).
 */
export function getRequiredDocs(measureName: string): string[] {
  return MEASURE_DOC_REQUIREMENTS[measureName as MeasureName] ?? [...BASE_DOCS];
}

/**
 * Human-readable label for a fileType enum value.
 * Matches the labels used in ContractorUploadModal FILE_TYPE_OPTIONS.
 */
export const FILE_TYPE_LABELS: Record<string, string> = {
  pre_photo: "Pre-Install Photos",
  mid_photo: "Mid-Install Photos",
  post_photo: "Post-Install Photos",
  loft_hatch_photo: "Loft Hatch & Draft Excluder Photos",
  dmev_photos: "DMEV Photos (Wetrooms)",
  door_undercut_photos: "Door Undercut Photos",
  trickle_vent_photos: "Trickle Vent Photos",
  pre_installation_building_inspection: "PIBI / Tech Survey",
  point_of_work_risk_assessment: "Point of Work Risk Assessment",
  claim_of_compliance: "DOCC 2030 (Claim of Compliance)",
  mcs_compliance_certificate: "MCS Compliance Certificate",
  certificate_of_conformity: "Certificate of Conformity",
  minor_works_electrical_certificate: "Minor Works Electrical Certificate",
  trustmark_licence_numbers: "TrustMark Licence Numbers",
  operative_competency: "Operative Competency",
  ventilation_assessment_checklist: "Ventilation Assessment Checklist",
  anemometer_readings: "Anemometer Readings",
  commissioning_records: "Commissioning Records",
  part_f_ventilation_document: "Approved Document Part F",
  handover_pack: "Handover Pack",
  workmanship_warranty: "Workmanship Warranty",
  insurance_guarantee: "Insurance Backed Guarantee (IBG)",
  g98_notification: "G98 / G99 Notification",
  installer_qualifications: "Installer Qualifications",
  installer_feedback: "Installer Feedback",
  contractor_other: "Other",
};
