import { describe, expect, test } from "bun:test";
import { AdvancedMdMcpReadGateway } from "./advancedmd-gateway.ts";
import type { McpToolCaller } from "./mcp-tool-client.ts";

describe("AdvancedMdMcpReadGateway", () => {
  test("maps AMD patient rows into verification candidates", async () => {
    const gateway = new AdvancedMdMcpReadGateway(
      fakeCaller({
        rows: [
          {
            id: "123",
            name: "Jane Smith",
            dob: "1980-01-02",
            homephone: "9725550100",
          },
        ],
      }),
    );

    const patients = await gateway.searchPatients("Jane Smith");
    expect(patients).toEqual([
      {
        patientId: "123",
        legalName: "Jane Smith",
        dob: "1980-01-02",
        phones: ["9725550100"],
      },
    ]);
  });
});

function fakeCaller(response: unknown): McpToolCaller {
  return {
    async callTool() {
      return response;
    },
    async listTools() {
      return [];
    },
    async close() {},
  };
}
