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

test("stop paths NO-MTG WR-LOAN WR-HEALTH DNC stay on blocked step 0", async ({ request }) => {
  const cases = [
    ["I rent", "NO-MTG"],
    ["I want to refinance my rate", "WR-LOAN"],
    ["I need health insurance", "WR-HEALTH"],
    ["do not call", "DNC"],
  ] as const;
  for (const [message, code] of cases) {
    const created = await createCase(request);
    const c = await sendChat(request, created.caseId, message);
    expect(c.stopPath, message).toBe(code);
    expect(c.status).toBe("stopped");
    expect(c.process.blocked).toBe(true);
    expect(c.process.step).toBe(0);
  }
});

test("step 4 emergency stop on chest pain", async ({ request }) => {
  const created = await createCase(request);
  const atFour = await sendMany(request, created.caseId, [
    STEP_SCRIPT.name,
    "Georgia",
    STEP_SCRIPT.intent,
    "I am 45 years old",
    "loan balance 120k usd, 12 years left",
    STEP_SCRIPT.build,
  ]);
  expect(atFour.process.step).toBe(4);
  const c = await sendChat(request, created.caseId, "chest pain now");
  expect(c.stopPath).toBe("EMERGENCY");
  expect(c.status).toBe("stopped");
});
