import assert from "node:assert/strict";
import test from "node:test";
import { computeProcess } from "@/lib/mortgage/gates";
import { heuristicPatch, mergeProfile } from "@/lib/mortgage/extract";
import { emptyProfile } from "@/lib/mortgage/schema";

test("LONG-01 loan once accepted is not still missing", () => {
  let p = emptyProfile();
  p = mergeProfile(p, heuristicPatch("My name is Pat Lee"));
  p = mergeProfile(p, heuristicPatch("Texas"));
  p = mergeProfile(p, heuristicPatch("I want mortgage protection on me only"));
  p = mergeProfile(p, heuristicPatch("I am 40 years old"));
  p = mergeProfile(p, heuristicPatch("loan balance 180000 usd, 20 years left"));
  assert.equal(p.loan_balance, 180000);
  const after = computeProcess(p);
  assert.ok(after.step >= 3);
  assert.ok(!after.missingRequired.includes("loan_balance"));
  // Later health/build answers must not clear loan
  p = mergeProfile(p, heuristicPatch(`5'8" 160 lb non-smoker`));
  p = mergeProfile(p, heuristicPatch("none of those"));
  assert.equal(p.loan_balance, 180000);
  assert.ok(!computeProcess(p).missingRequired.includes("loan_balance"));
});
