/**
 * Mock fixtures 完整性测试
 *
 * 确保所有 mock 数据导出存在且符合基本结构约束
 */
import { describe, expect, it } from "vitest";
import {
  mockCurrentUser,
  mockPermissions,
  mockRoles,
  mockUsers,
  mockViewports,
  mockOrganization,
  mockClasses,
  mockTeachers,
  mockStudents,
  mockAuditLogs,
  mockDashboard,
  mockSystemSettings,
  mockSchools,
  mockGrades,
  mockGradeInsights,
  mockDepartments,
  mockAcademicYears,
  mockAuditOverviewStats,
  mockAuditTrend,
  mockDataChangeLogs,
  mockLoginLogs,
  mockAnnouncements,
  mockInvitationCodes,
  mockFiles,
  mockFileStats,
  mockAiProviders,
  mockAiUsage,
  mockSecurityPolicy,
  mockFileUploadConfig,
  mockNotificationConfig,
  mockBrandConfig,
  genId,
} from "./fixtures";

describe("mock fixtures 完整性", () => {
  it("mockCurrentUser 包含管理员权限", () => {
    expect(mockCurrentUser.id).toBeTruthy();
    expect(mockCurrentUser.permissions).toContain("ADMIN_DASHBOARD_VIEW");
    expect(mockCurrentUser.permissions.length).toBeGreaterThan(10);
  });

  it("mockPermissions 非空且每条有 code", () => {
    expect(mockPermissions.length).toBeGreaterThan(10);
    for (const p of mockPermissions) {
      expect(p.code).toBeTruthy();
      expect(p.id).toBeTruthy();
    }
  });

  it("mockRoles 包含系统管理员", () => {
    expect(mockRoles.length).toBeGreaterThanOrEqual(4);
    const sysAdmin = mockRoles.find((r) => r.code === "system_admin");
    expect(sysAdmin).toBeDefined();
    expect(sysAdmin?.dataScope).toBe("ALL");
  });

  it("mockUsers 非空", () => {
    expect(mockUsers.length).toBeGreaterThanOrEqual(3);
    for (const u of mockUsers) {
      expect(u.email).toContain("@");
      expect(u.id).toBeTruthy();
    }
  });

  it("mockViewports 覆盖所有 scope", () => {
    const scopes = new Set(mockViewports.map((v) => v.scope));
    expect(scopes.has("teacher")).toBe(true);
    expect(scopes.has("student")).toBe(true);
    expect(scopes.has("parent")).toBe(true);
    expect(scopes.has("admin")).toBe(true);
  });

  it("mockOrganization 树形结构有根节点", () => {
    const roots = mockOrganization.filter((n) => n.parentId === null);
    expect(roots.length).toBeGreaterThan(0);
  });

  it("mockClasses/Teachers/Students 非空", () => {
    expect(mockClasses.length).toBeGreaterThan(0);
    expect(mockTeachers.length).toBeGreaterThan(0);
    expect(mockStudents.length).toBeGreaterThan(0);
  });

  it("mockAuditLogs 非空且有时间戳", () => {
    expect(mockAuditLogs.length).toBeGreaterThan(0);
    for (const log of mockAuditLogs) {
      expect(typeof log.occurredAt).toBe("number");
      expect(log.action).toBeTruthy();
    }
  });

  it("mockDashboard 包含基础统计", () => {
    expect(mockDashboard).toBeDefined();
    expect(typeof mockDashboard).toBe("object");
  });

  it("mockSystemSettings 非空", () => {
    expect(mockSystemSettings).toBeDefined();
  });

  it("学校组织 mock 数据完整", () => {
    expect(mockSchools.length).toBeGreaterThan(0);
    expect(mockGrades.length).toBeGreaterThan(0);
    expect(mockDepartments.length).toBeGreaterThan(0);
    expect(mockAcademicYears.length).toBeGreaterThan(0);
    expect(mockGradeInsights).toBeDefined();
  });

  it("审计子模块 mock 数据完整", () => {
    expect(mockAuditOverviewStats).toBeDefined();
    expect(mockAuditTrend.length).toBe(7);
    expect(mockDataChangeLogs.length).toBeGreaterThan(0);
    expect(mockLoginLogs.length).toBeGreaterThan(0);
  });

  it("公告/邀请码/文件 mock 数据完整", () => {
    expect(mockAnnouncements.length).toBeGreaterThan(0);
    expect(mockInvitationCodes.length).toBeGreaterThan(0);
    expect(mockFiles.length).toBeGreaterThan(0);
    expect(mockFileStats).toBeDefined();
  });

  it("AI 设置 mock 数据完整", () => {
    expect(mockAiProviders.length).toBeGreaterThan(0);
    expect(mockAiUsage).toBeDefined();
  });

  it("系统设置增强 mock 数据完整", () => {
    expect(mockSecurityPolicy).toBeDefined();
    expect(mockFileUploadConfig).toBeDefined();
    expect(mockNotificationConfig).toBeDefined();
    expect(mockBrandConfig).toBeDefined();
  });

  it("genId 生成唯一 ID", () => {
    const id1 = genId("test");
    const id2 = genId("test");
    expect(id1).not.toBe(id2);
    expect(id1.startsWith("test-")).toBe(true);
  });
});
