import { describe, expect, it } from "vitest";
import { resolveProvenanceSignal } from "./provenance";

describe("resolveProvenanceSignal", () => {
  it("flags a predicted-only property as estimated, even when rebaselined", () => {
    expect(
      resolveProvenanceSignal({
        isNewApproach: true,
        hasLodgedEpc: false,
        hasPredictedEpc: true,
        rebaselineReason: "pre_sap10",
      }),
    ).toBe("estimated");
  });

  it("flags a lodged, rebaselined property as remodelled", () => {
    expect(
      resolveProvenanceSignal({
        isNewApproach: true,
        hasLodgedEpc: true,
        hasPredictedEpc: false,
        rebaselineReason: "pre_sap10",
      }),
    ).toBe("remodelled");
  });

  it("returns none for a lodged property that was not rebaselined", () => {
    expect(
      resolveProvenanceSignal({
        isNewApproach: true,
        hasLodgedEpc: true,
        hasPredictedEpc: false,
        rebaselineReason: "none",
      }),
    ).toBe("none");
  });

  it("prefers the real certificate when both lodged and predicted EPCs exist", () => {
    expect(
      resolveProvenanceSignal({
        isNewApproach: true,
        hasLodgedEpc: true,
        hasPredictedEpc: true,
        rebaselineReason: "pre_sap10",
      }),
    ).toBe("remodelled");
  });

  it("returns none for legacy properties regardless of EPC inputs", () => {
    expect(
      resolveProvenanceSignal({
        isNewApproach: false,
        hasLodgedEpc: false,
        hasPredictedEpc: true,
        rebaselineReason: "pre_sap10",
      }),
    ).toBe("none");
  });
});
