// MSW mock fixtures：模拟 parent-bff GraphQL + iam login 响应
// 依据：
// - ISSUE-010 iam GetChildrenByParent P0 阻塞 → 用 mock（student-001 + student-002）
// - 02-architecture-design.md §8 MSW 模拟未就绪上游
// - F9 GraphQL（所有查询走 GraphQL）
// - ISSUE-004 登录端点走 REST

import type {
  UserSession,
  ChildInfo,
  ChildSummary,
  GradeDataPoint,
  AttendanceRecord,
  HomeworkItem,
  WeaknessPoint,
  LearningTrend,
  NotificationItem,
  NotificationPreferences,
  LoginResponse,
} from "@/types";

// ===== 用户 =====
export const mockParent: UserSession = {
  id: "parent-001",
  email: "parent@example.com",
  name: "张父",
  roles: ["parent"],
  permissions: [
    "DASHBOARD_VIEW",
    "CHILD_GRADE_VIEW",
    "CHILD_ATTENDANCE_VIEW",
    "CHILD_HOMEWORK_VIEW",
    "CHILD_WEAKNESS_VIEW",
    "NOTIFICATION_VIEW",
    "NOTIFICATION_PREFERENCE_UPDATE",
  ],
  dataScope: "CHILDREN",
  schoolId: "school-001",
};

// ===== 子女列表（ISSUE-010：iam P0 阻塞，用 mock）=====
export const mockChildren: ChildInfo[] = [
  {
    id: "student-001",
    name: "张小明",
    grade: "grade.7",
    schoolName: "实验中学",
    classId: "class-7-1",
    className: "初一(1)班",
  },
  {
    id: "student-002",
    name: "张小红",
    grade: "grade.5",
    schoolName: "实验小学",
    classId: "class-5-2",
    className: "五年级(2)班",
  },
];

// ===== 成绩数据点 =====
export const mockGradeDataPoints: GradeDataPoint[] = [
  {
    examId: "exam-001",
    examName: "期中数学测验",
    examDate: "2026-03-15T09:00:00Z",
    subject: "数学",
    studentScore: 92,
    classAverage: 78,
    classMax: 100,
    classMin: 45,
    gradeLevel: "A",
  },
  {
    examId: "exam-002",
    examName: "期中语文测验",
    examDate: "2026-03-16T09:00:00Z",
    subject: "语文",
    studentScore: 85,
    classAverage: 75,
    classMax: 95,
    classMin: 52,
    gradeLevel: "B",
  },
  {
    examId: "exam-003",
    examName: "期中英语测验",
    examDate: "2026-03-17T09:00:00Z",
    subject: "英语",
    studentScore: 88,
    classAverage: 72,
    classMax: 98,
    classMin: 40,
    gradeLevel: "B",
  },
  {
    examId: "exam-004",
    examName: "月考物理",
    examDate: "2026-04-10T09:00:00Z",
    subject: "物理",
    studentScore: 95,
    classAverage: 80,
    classMax: 100,
    classMin: 50,
    gradeLevel: "A",
  },
];

// ===== 子女概览 =====
export const mockChildSummary: ChildSummary = {
  childId: "student-001",
  avgScore: 90,
  classRank: 5,
  classSize: 45,
  attendanceRate: 0.96,
  pendingHomeworkCount: 3,
  recentGradeTrend: "up",
  recentScores: mockGradeDataPoints,
  upcomingEvents: [
    {
      id: "event-001",
      type: "exam",
      title: "期末数学考试",
      dueDate: "2026-07-20T09:00:00Z",
    },
    {
      id: "event-002",
      type: "homework",
      title: "物理实验报告",
      dueDate: "2026-07-12T23:59:59Z",
    },
  ],
};

// ===== 考勤记录 =====
export const mockAttendance: AttendanceRecord[] = (() => {
  const records: AttendanceRecord[] = [];
  const baseDate = new Date("2026-06-01");
  for (let i = 0; i < 22; i++) {
    const d = new Date(baseDate);
    d.setDate(d.getDate() + i);
    // 周末跳过
    const day = d.getDay();
    if (day === 0 || day === 6) continue;
    let status: AttendanceRecord["status"] = "present";
    if (i === 5) status = "late";
    if (i === 12) status = "leave";
    records.push({
      id: `att-${i}`,
      date: d.toISOString().slice(0, 10),
      status,
    });
  }
  return records;
})();

// ===== 作业列表 =====
export const mockHomework: HomeworkItem[] = [
  {
    id: "hw-001",
    title: "数学第三章习题",
    subject: "数学",
    className: "初一(1)班",
    assignedDate: "2026-07-01T09:00:00Z",
    dueDate: "2026-07-10T23:59:59Z",
    status: "in_progress",
    maxScore: 100,
  },
  {
    id: "hw-002",
    title: "语文古诗文背诵",
    subject: "语文",
    className: "初一(1)班",
    assignedDate: "2026-06-28T09:00:00Z",
    dueDate: "2026-07-08T23:59:59Z",
    status: "submitted",
    maxScore: 50,
  },
  {
    id: "hw-003",
    title: "英语听力练习",
    subject: "英语",
    className: "初一(1)班",
    assignedDate: "2026-07-05T09:00:00Z",
    dueDate: "2026-07-12T23:59:59Z",
    status: "not_started",
    maxScore: 30,
  },
  {
    id: "hw-004",
    title: "物理实验报告",
    subject: "物理",
    className: "初一(1)班",
    assignedDate: "2026-06-20T09:00:00Z",
    dueDate: "2026-06-25T23:59:59Z",
    status: "graded",
    score: 28,
    maxScore: 30,
    feedback: "实验步骤完整，数据分析准确。",
  },
];

// ===== 学情薄弱点 =====
export const mockWeakness: WeaknessPoint[] = [
  {
    id: "wp-001",
    knowledgePoint: "一元二次方程",
    masteryLevel: 0.45,
    subject: "数学",
    recommendation: "建议复习配方法，完成针对性练习 20 道",
  },
  {
    id: "wp-002",
    knowledgePoint: "文言文虚词",
    masteryLevel: 0.6,
    subject: "语文",
    recommendation: "建议背诵常见虚词用法表",
  },
  {
    id: "wp-003",
    knowledgePoint: "现在完成时",
    masteryLevel: 0.72,
    subject: "英语",
  },
];

// ===== 学习趋势 =====
export const mockLearningTrend: LearningTrend = {
  childId: "student-001",
  period: "month",
  dataPoints: [
    { date: "2026-03", score: 82, subject: "数学" },
    { date: "2026-04", score: 88, subject: "数学" },
    { date: "2026-05", score: 92, subject: "数学" },
    { date: "2026-06", score: 90, subject: "数学" },
  ],
};

// ===== 通知列表 =====
export const mockNotifications: NotificationItem[] = [
  {
    id: "notif-001",
    childId: "student-001",
    eventType: "grade_recorded",
    title: "grade_recorded.title",
    body: "grade_recorded.body",
    read: false,
    createdAt: new Date(Date.now() - 3600000).toISOString(),
    actionUrl: "/parent/grades?childId=student-001",
    pinned: true,
  },
  {
    id: "notif-002",
    childId: "student-001",
    eventType: "homework_assigned",
    title: "homework_assigned.title",
    body: "homework_assigned.body",
    read: false,
    createdAt: new Date(Date.now() - 7200000).toISOString(),
    actionUrl: "/parent/homework?childId=student-001",
  },
  {
    id: "notif-003",
    childId: null,
    eventType: "school_announcement",
    title: "school_announcement.title",
    body: "school_announcement.body",
    read: true,
    createdAt: new Date(Date.now() - 86400000).toISOString(),
  },
];

// ===== 通知偏好默认值（ISSUE-033：P4 localStorage 降级）=====
export const mockNotificationPreferences: NotificationPreferences = {
  parentId: "parent-001",
  preferences: {
    "student-001": {
      grade_recorded: { in_app: true, push: true },
      homework_graded: { in_app: true, push: true },
      homework_assigned: { in_app: true, push: true },
      exam_published: { in_app: true, push: true, sms: false },
      attendance_alert: { in_app: true, push: true, sms: true },
      school_announcement: { in_app: true },
      teacher_message: { in_app: true, push: true },
      fee_reminder: { in_app: true, push: true, sms: true },
      event_invitation: { in_app: true, push: true },
    },
    "student-002": {
      grade_recorded: { in_app: true, push: true },
      homework_graded: { in_app: true, push: true },
      homework_assigned: { in_app: true, push: true },
      exam_published: { in_app: true, push: true },
      attendance_alert: { in_app: true, push: true, sms: true },
      school_announcement: { in_app: true },
      teacher_message: { in_app: true, push: true },
      fee_reminder: { in_app: true, push: true, sms: true },
      event_invitation: { in_app: true, push: true },
    },
  },
  defaults: {
    grade_recorded: { in_app: true, push: true },
    homework_graded: { in_app: true, push: true },
    homework_assigned: { in_app: true, push: true },
    exam_published: { in_app: true, push: true },
    attendance_alert: { in_app: true, push: true, sms: true },
    school_announcement: { in_app: true },
    teacher_message: { in_app: true, push: true },
    fee_reminder: { in_app: true, push: true, sms: true },
    event_invitation: { in_app: true, push: true },
  },
  updatedAt: new Date().toISOString(),
};

// ===== 登录响应（ISSUE-004：REST 登录）=====
export const mockLoginResponse: LoginResponse = {
  user: mockParent,
  tokens: {
    accessToken: "mock-access-token-parent-001",
    refreshToken: "mock-refresh-token-parent-001",
    expiresIn: 3600,
  },
};
