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 quickAssignPermissions = [
  PermissionKey.MANAGE_ALLOCATIONS,
  PermissionKey.USE_ASSISTANT_ADVANCED_TOOLS,
];

export const quickAssignRole = SystemRole.MANAGER;

export function createQuickAssignInput(overrides: Record<string, unknown> = {}) {
  return {
    resourceIdentifier: "resource_1",
    projectIdentifier: "project_1",
    startDate: "2026-03-16",
    endDate: "2026-03-20",
    hoursPerDay: 8,
    ...overrides,
  };
}

export function createCreatedAssignment(overrides: Record<string, unknown> = {}) {
  return {
    id: "assignment_quick_1",
    demandRequirementId: null,
    resourceId: "resource_1",
    projectId: "project_1",
    startDate: new Date("2026-03-16"),
    endDate: new Date("2026-03-20"),
    hoursPerDay: 8,
    percentage: 100,
    role: "Team Member",
    roleId: null,
    dailyCostCents: 40000,
    status: "PROPOSED",
    metadata: { source: "quickAssign" },
    createdAt: new Date("2026-03-13"),
    updatedAt: new Date("2026-03-13"),
    resource: {
      id: "resource_1",
      displayName: "Alice",
      eid: "E-001",
      lcrCents: 5000,
    },
    project: {
      id: "project_1",
      name: "Gelddruckmaschine",
      shortCode: "GDM",
      status: "ACTIVE",
      responsiblePerson: null,
    },
    roleEntity: null,
    demandRequirement: null,
    ...overrides,
  };
}

export const executeTool = executeAssistantTool;
