import { expect, test } from "@playwright/test";
import { createCase, openCaseOnStep, patchProfile } from "./helpers";

test("step 6 Soft decision: DecisionResult is the exit gate", async ({ request, page }) => {
  const created = await createCase(request);
  const atSix = await patchProfile(request, created.caseId, {
    name: "Pat Lee",
    state: "FL",
    intent: "mortgage_protection",
    coverage_on_whom: "primary",
    age: 40,
    loan_balance: 180000,
    loan_term_years: 20,
    height_ft_in: "5'8\"",
    weight_lb: 160,
    tobacco_answered: true,
    tobacco_products: ["None"],
    diseases_complete: true,
    diseases_none_reported: true,
    beneficiary_relationship: "self",
    annual_income: 85000,
  });
  expect(atSix.process.step).toBe(6);
  expect(atSix.process.missingRequired).toEqual(expect.arrayContaining(["decision_result"]));
  expect(atSix.profile.decision_result).toBeFalsy();

  await openCaseOnStep(page, atSix.caseId);
  await expect(page.getByTestId("process-current")).toHaveText("Soft decision");
  await expect(page.getByTestId("process-exit-gate")).toContainText("DecisionResult persisted");

  const next = await patchProfile(request, created.caseId, {
    decision_result: {
      offer_family: "si_level",
      reasons: ["test"],
      drivers: [],
      suggested_next_step: "agent",
    },
  });
  expect(next.profile.decision_result).toBeTruthy();
  expect(next.process.step).toBeGreaterThanOrEqual(6);
});
