import type { WizardPrompter } from "minion/plugin-sdk";
import { beforeEach, describe, expect, it, vi } from "vitest";

vi.mock("minion/plugin-sdk", () => ({
  formatDocsLink: (_url: string, fallback: string) => fallback,
  addWildcardAllowFrom: vi.fn((x) => x),
  mergeAllowFromEntries: vi.fn((a, b) => [...a, ...b]),
  promptChannelAccessConfig: vi.fn(async () => null),
  DEFAULT_ACCOUNT_ID: "default",
}));

vi.mock("./resolve-allowlist.js", () => ({
  parseMSTeamsTeamEntry: vi.fn(),
  resolveMSTeamsChannelAllowlist: vi.fn(async () => []),
  resolveMSTeamsUserAllowlist: vi.fn(async () => []),
}));

vi.mock("./token.js", () => ({
  resolveMSTeamsCredentials: vi.fn(() => null),
}));

describe("notePrivacyNotice (msteams onboarding)", () => {
  const mockNote = vi.fn();
  const mockPrompter: WizardPrompter = {
    note: mockNote,
  } as unknown as WizardPrompter;

  beforeEach(() => {
    vi.clearAllMocks();
  });

  it("shows privacy notice with GDPR reference", async () => {
    const { notePrivacyNotice } = await import("./onboarding.js");
    await notePrivacyNotice(mockPrompter);

    expect(mockNote).toHaveBeenCalledOnce();
    const [content, title] = mockNote.mock.calls[0] as [string, string];
    expect(content).toContain("GDPR Art. 13");
    expect(content).toContain("EU AI Act Art. 50");
    expect(title).toBe("Privacy notice");
  });

  it("includes privacy notice link in note content", async () => {
    const { notePrivacyNotice } = await import("./onboarding.js");
    await notePrivacyNotice(mockPrompter);

    const [content] = mockNote.mock.calls[0] as [string];
    expect(content).toContain("privacy-notice");
  });

  it("discloses AI provider data processing", async () => {
    const { notePrivacyNotice } = await import("./onboarding.js");
    await notePrivacyNotice(mockPrompter);

    const [content] = mockNote.mock.calls[0] as [string];
    expect(content).toContain("AI model providers");
    expect(content).toContain("Conversation history");
  });

  it("mentions data subject rights", async () => {
    const { notePrivacyNotice } = await import("./onboarding.js");
    await notePrivacyNotice(mockPrompter);

    const [content] = mockNote.mock.calls[0] as [string];
    expect(content).toContain("access, correction, or erasure");
  });
});
