import type { ApplicantProfile } from "./schema";

export function stubDecision(p: ApplicantProfile): ApplicantProfile["decision_result"] {
  const bmi = p.bmi_computed ?? 0;
  const imps = p.impairments || [];
  const drivers: string[] = [];
  const reasons: string[] = [];

  if (p.diseases_none_reported) reasons.push("No disease modules disclosed");
  if (bmi > 0 && bmi <= 42) {
    drivers.push(`BMI ${bmi}`);
    reasons.push("Build within typical SI Level/Graded ceiling");
  }
  if (bmi > 46) {
    drivers.push(`BMI ${bmi}`);
    reasons.push("Build often GI / traditional decline");
    return {
      offer_family: "gi",
      reasons,
      drivers,
      suggested_next_step: "Discuss GI with a licensed agent",
    };
  }
  const hard = imps.some((i) =>
    ["dialysis", "oxygen", "metastatic", "chf"].some((k) =>
      JSON.stringify(i.attributes).toLowerCase().includes(k)
    )
  );
  if (hard) {
    return {
      offer_family: "graded",
      reasons: [...reasons, "Impairment flags may block Level"],
      drivers,
      suggested_next_step: "Licensed agent shops Graded/GI",
    };
  }
  const family = bmi > 42 ? "graded" : "si_level";
  return {
    offer_family: family,
    reasons: reasons.length ? reasons : ["Illustrative path from build + disclosures"],
    drivers,
    suggested_next_step: "Hand off to licensed agent for carrier quote",
  };
}

export const STUB_CARRIERS = ["Appointed SI carrier A", "Appointed SI carrier B"];
