import { describe, expect, it, vi } from "vitest";
import { SystemRole } from "@capakraken/shared";

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([]),
  };
});

import { executeTool } from "../router/assistant-tools.js";
import { createToolContext, withUserLookup } from "./assistant-tools-notification-test-helpers.js";

describe("assistant reminder list tools", () => {
  it("lists reminders through the real router path for the current user", async () => {
    const db = withUserLookup({
      notification: {
        findMany: vi.fn().mockResolvedValue([
          {
            id: "rem_1",
            userId: "user_1",
            category: "REMINDER",
            title: "Check holiday setup",
            nextRemindAt: new Date("2026-05-01T07:00:00.000Z"),
          },
        ]),
      },
    });
    const ctx = createToolContext(db, SystemRole.USER);

    const result = await executeTool(
      "list_reminders",
      JSON.stringify({ limit: 10 }),
      ctx,
    );

    expect(db.notification.findMany).toHaveBeenCalledWith({
      where: { userId: "user_1", category: "REMINDER" },
      orderBy: { nextRemindAt: "asc" },
      take: 10,
    });
    expect(JSON.parse(result.content)).toEqual([
      expect.objectContaining({
        id: "rem_1",
        title: "Check holiday setup",
        category: "REMINDER",
      }),
    ]);
  });
});
