/**
 * Provenance signal — what the user is told about an EPC's trustworthiness.
 * See CONTEXT.md ("EPC provenance", "Provenance signal") and ADR-0002.
 *
 * Pure decision over a property's EPC provenance (`epc_property.source`) and its
 * Rebaseline (`property_baseline_performance.rebaseline_reason`). The DB-reading
 * resolver gathers the inputs; this function owns the precedence.
 */
export type ProvenanceSignal = "estimated" | "remodelled" | "none";

export function resolveProvenanceSignal(input: {
  isNewApproach: boolean;
  hasLodgedEpc: boolean;
  hasPredictedEpc: boolean;
  rebaselineReason: string | null | undefined;
}): ProvenanceSignal {
  // Legacy (pre-cutoff) properties have no effective/lodged split and no
  // provenance concept — they read the property row directly.
  if (!input.isNewApproach) {
    return "none";
  }
  // No EPC certificate exists — the picture was estimated from nearby homes.
  // Dominant: wins even when the baseline was also rebaselined.
  if (input.hasPredictedEpc && !input.hasLodgedEpc) {
    return "estimated";
  }
  // A real certificate exists but the modelling baseline diverged from it.
  if (
    input.hasLodgedEpc &&
    input.rebaselineReason != null &&
    input.rebaselineReason !== "none"
  ) {
    return "remodelled";
  }
  return "none";
}
