import { expect, test } from "@playwright/test";
import { createCase, sendChat, sendMany, STEP_SCRIPT, TO_STEP_4 } from "./helpers";

/**
 * Dataset/process expected behavior vs CURRENT chat+gates.
 * test.fail() = expected application gaps. Suite stays green until product is fixed
 * (then these fail as unexpected-pass and should be converted to normal tests).
 */

test("GAP-S4-LUNG: process HTML lists lung in disease interview; none of those should clear lung", async ({
  request,
}) => {
  test.fail(true, "R_DISEASE omits lung; none of those does not set lung=no");
  const created = await createCase(request);
  const c = await sendMany(request, created.caseId, [...TO_STEP_4, "none of those"]);
  expect(c.profile.disease_screens as Record<string, string>).toMatchObject({ lung: "no" });
});

test("GAP-S2-SEX: dataset marks sex R; female disclosure should populate sex", async ({ request }) => {
  test.fail(true, "heuristic extract does not set sex");
  const created = await createCase(request);
  await sendMany(request, created.caseId, ["My name is Jane Doe", "Texas", STEP_SCRIPT.intent]);
  const c = await sendChat(request, created.caseId, "I am a 40 year old woman");
  expect(c.profile.age).toBe(40);
  expect(c.profile.sex).toBeTruthy();
});

test("S1-PHRASE: I want to protect my mortgage, just on me locks intent", async ({ request }) => {
  const created = await createCase(request);
  await sendMany(request, created.caseId, ["My name is John Smith", "Texas"]);
  const c = await sendChat(request, created.caseId, "I want to protect my mortgage, just on me");
  expect(c.profile.intent).toBe("mortgage_protection");
  expect(c.profile.coverage_on_whom).toBe("primary");
});

test("GAP-S6-DIALYSIS: chat I'm on dialysis should graded (stub scans attributes only)", async ({
  request,
}) => {
  test.fail(true, "stubDecision looks for 'dialysis' in attributes, chat only sets disclosed");
  const created = await createCase(request);
  const c = await sendMany(request, created.caseId, [
    STEP_SCRIPT.name,
    STEP_SCRIPT.state,
    STEP_SCRIPT.intent,
    STEP_SCRIPT.age,
    STEP_SCRIPT.loan,
    STEP_SCRIPT.build,
    "I'm on dialysis",
    "Rest of my health is good",
    STEP_SCRIPT.income,
  ]);
  expect((c.profile.decision_result as { offer_family?: string })?.offer_family).toBe("graded");
});
