import { describe, expect, it } from "vitest";
import {
  BASE_DOCS,
  MEASURE_DOC_REQUIREMENTS,
  MEASURE_NAMES,
  getRequiredDocs,
} from "./measureDocumentRequirements";

describe("MEASURE_NAMES catalogue", () => {
  it("includes every measure keyed in MEASURE_DOC_REQUIREMENTS", () => {
    for (const name of Object.keys(MEASURE_DOC_REQUIREMENTS)) {
      expect(MEASURE_NAMES).toContain(name);
    }
  });

  it("includes the names called out in the trailing comment as base-only", () => {
    const baseOnly = [
      "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",
    ];
    for (const name of baseOnly) {
      expect(MEASURE_NAMES).toContain(name);
    }
  });
});

describe("getRequiredDocs", () => {
  it("returns the explicit doc list for a known measure", () => {
    const docs = getRequiredDocs("ASHP");
    // ASHP gets BASE + MCS_EXTRA + commissioning_records
    expect(docs).toEqual([
      ...BASE_DOCS,
      "mcs_compliance_certificate",
      "commissioning_records",
    ]);
  });

  it("returns Solar PV's specific docs (with G98 notification)", () => {
    const docs = getRequiredDocs("Solar PV");
    expect(docs).toContain("g98_notification");
    expect(docs).toContain("mcs_compliance_certificate");
  });

  it("returns BASE_DOCS for a measure that only requires the baseline", () => {
    const docs = getRequiredDocs("CWI");
    expect(docs).toEqual([...BASE_DOCS]);
  });

  it("returns BASE_DOCS for an unknown measure name", () => {
    const docs = getRequiredDocs("Definitely Not A Real Measure");
    expect(docs).toEqual([...BASE_DOCS]);
  });

  it("returns a fresh array (mutating the result must not affect BASE_DOCS)", () => {
    const docs = getRequiredDocs("Unknown");
    docs.push("mutation");
    expect(BASE_DOCS).not.toContain("mutation");
  });
});
