import { beforeEach, describe, expect, it, vi } from "vitest";
import { SystemRole } from "@capakraken/shared";
import {
  createToolContext,
  executeTool,
  resetAssistantImportToolTestState,
} from "./assistant-tools-import-dispo-webhooks-test-helpers.js";

describe("assistant project export tools", () => {
  beforeEach(async () => {
    await resetAssistantImportToolTestState();
  });

  it("exports projects CSV through the real import/export router path", async () => {
    const ctx = createToolContext(
      {
        project: {
          findMany: vi.fn().mockResolvedValue([
            {
              shortCode: "APO",
              name: "Apollo",
              orderType: "CHARGEABLE",
              status: "ACTIVE",
              budgetCents: 125000,
              startDate: new Date("2026-02-01T00:00:00.000Z"),
              endDate: new Date("2026-02-28T00:00:00.000Z"),
              winProbability: 80,
              dynamicFields: {},
            },
          ]),
        },
        blueprint: {
          findMany: vi.fn().mockResolvedValue([]),
        },
      },
      { userRole: SystemRole.CONTROLLER },
    );

    const result = await executeTool("export_projects_csv", "{}", ctx);

    expect(JSON.parse(result.content)).toEqual({
      format: "csv",
      lineCount: 2,
      csv: "shortCode,name,orderType,status,budgetCents,startDate,endDate,winProbability\nAPO,Apollo,CHARGEABLE,ACTIVE,125000,2026-02-01,2026-02-28,80",
    });
  });
});
