import { PermissionKey, SystemRole } from "@capakraken/shared";
import { vi } from "vitest";

vi.mock("@capakraken/application", async (importOriginal) => {
  const actual = await importOriginal<typeof import("@capakraken/application")>();
  return {
    ...actual,
    getDashboardBudgetForecast: vi.fn().mockResolvedValue([]),
    getDashboardPeakTimes: vi.fn().mockResolvedValue([]),
    listAssignmentBookings: vi.fn().mockResolvedValue([]),
  };
});

vi.mock("../sse/event-bus.js", () => ({
  emitAllocationCreated: vi.fn(),
  emitAllocationDeleted: vi.fn(),
  emitAllocationUpdated: vi.fn(),
  emitProjectShifted: vi.fn(),
}));

vi.mock("../lib/budget-alerts.js", () => ({
  checkBudgetThresholds: vi.fn(),
}));

vi.mock("../lib/cache.js", () => ({
  invalidateDashboardCache: vi.fn(),
}));

import { executeTool as executeAssistantTool } from "../router/assistant-tools.js";

export { createToolContext } from "./assistant-tools-advanced-timeline-test-helpers.js";
export {
  buildBaseProject,
  buildBaseResource,
} from "./assistant-tools-timeline-allocation-mutation-test-helpers.js";

export const batchQuickAssignPermissions = [
  PermissionKey.MANAGE_ALLOCATIONS,
  PermissionKey.USE_ASSISTANT_ADVANCED_TOOLS,
];

export const batchQuickAssignRole = SystemRole.MANAGER;

export function createBatchQuickAssignInput(
  overrides: Array<Record<string, unknown>> = [],
) {
  const baseAssignments = [
    {
      resourceIdentifier: "resource_1",
      projectIdentifier: "project_1",
      startDate: "2026-03-16",
      endDate: "2026-03-20",
      hoursPerDay: 8,
    },
    {
      resourceIdentifier: "resource_2",
      projectIdentifier: "project_1",
      startDate: "2026-03-23",
      endDate: "2026-03-27",
      hoursPerDay: 6,
    },
  ];

  return {
    assignments: baseAssignments.map((assignment, index) => ({
      ...assignment,
      ...(overrides[index] ?? {}),
    })),
  };
}

export const executeTool = executeAssistantTool;
