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

test("AI-060 hyphenated name Mary-Jane", () => {
  assert.equal(extractPersonName("My name is Mary-Jane Watson"), "Mary-Jane Watson");
});

test("AI-061 apostrophe name O'Connor", () => {
  assert.equal(extractPersonName("My name is O'Connor"), "O'Connor");
});

test("AI-062 numeric name rejected", () => {
  const p = mergeProfile(emptyProfile(), heuristicPatch("My name is 12345"));
  assert.equal(p.name, undefined);
});

test("AI-069 AI-070 phone spaces and hyphens", () => {
  assert.equal(heuristicPatch("call 555 123 4567").phone, "555 123 4567");
  assert.equal(heuristicPatch("call 555-123-4567").phone, "555-123-4567");
});

test("AI-071 parenthetical phone is not captured by current regex", () => {
  assert.equal(heuristicPatch("call (555) 123-4567").phone, undefined);
});

test("AI-077 TX abbreviation", () => {
  assert.equal(parseUsState("TX"), "TX");
  assert.equal(heuristicPatch("I live in TX").state, "TX");
});

test("AI-369 Washington maps to WA not DC", () => {
  assert.equal(parseUsState("I live in Washington"), "WA");
});

test("AI-121 cigar maps to E-cigar product bucket", () => {
  assert.deepEqual(heuristicPatch("I smoke cigars").tobacco_products, ["E-cigar"]);
});

test("AI-122 vape maps to E-cigar product bucket", () => {
  assert.deepEqual(heuristicPatch("I vape").tobacco_products, ["E-cigar"]);
});

test("AI-108 negative loan is not stored", () => {
  assert.equal(heuristicPatch("loan balance is $-50000").loan_balance, undefined);
});
