async function chat(base: string, msg: string) {
  const cRes = await fetch(base + "/api/mortgage/case", { method: "POST" });
  const c = await cRes.json();
  if (!c.caseId) {
    console.log(JSON.stringify({ m: msg, error: c, status: cRes.status }));
    return;
  }
  const outRes = await fetch(base + "/api/mortgage/chat", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ caseId: c.caseId, message: msg }),
  });
  const out = await outRes.json();
  console.log(
    JSON.stringify({
      m: msg,
      http: outRes.status,
      status: out.status,
      stopPath: out.stopPath,
      blocked: out.process?.blocked,
      loan: out.profile?.loan_balance ?? null,
      dob: out.profile?.date_of_birth ?? null,
      reply: (out.messages || [])
        .filter((x: { role: string }) => x.role === "assistant")
        .pop()
        ?.content?.slice(0, 140),
    })
  );
}

async function main() {
  const base = process.argv[2] || "https://mortgage.gventure.live";
  for (const m of [
    "I want health insurance.",
    "Is mortgage protection the same as health insurance?",
    "loan balance is -100000",
    "My DOB is 01/01/2035",
  ]) {
    await chat(base, m);
  }
}

main().catch((e) => {
  console.error(e);
  process.exit(1);
});

export {};
