/**
 * Mock 学情分析数据（data-ana / ai 域，P4 扩展）
 *
 * 维护者：ai13（teacher-portal）
 */

import type {
  ClassAnalytics,
  StudentAnalytics,
} from "@/lib/graphql-p4";

/** Top 学生 mock（5 名，含趋势 / 弱项 / 强项） */
const topStudents: StudentAnalytics[] = [
  {
    studentId: "stu-001",
    studentName: "学生01",
    avgScore: 92,
    trend: [88, 90, 85, 91, 94],
    weakPoints: ["导数", "书面表达"],
    strongPoints: ["实数与运算", "词汇基础"],
    masteryRate: 90,
  },
  {
    studentId: "stu-002",
    studentName: "学生02",
    avgScore: 89,
    trend: [85, 87, 86, 90, 92],
    weakPoints: ["函数", "议论文写作"],
    strongPoints: ["代数式", "语法结构"],
    masteryRate: 84,
  },
  {
    studentId: "stu-003",
    studentName: "学生03",
    avgScore: 86,
    trend: [80, 83, 85, 88, 90],
    weakPoints: ["方程与不等式", "阅读理解"],
    strongPoints: ["文言文基础", "词汇基础"],
    masteryRate: 78,
  },
  {
    studentId: "stu-004",
    studentName: "学生04",
    avgScore: 84,
    trend: [78, 82, 80, 86, 88],
    weakPoints: ["函数", "现代文阅读"],
    strongPoints: ["实数与运算", "古诗词鉴赏"],
    masteryRate: 72,
  },
  {
    studentId: "stu-005",
    studentName: "学生05",
    avgScore: 81,
    trend: [75, 79, 82, 84, 85],
    weakPoints: ["导数", "书面表达", "阅读理解"],
    strongPoints: ["词汇基础", "代数式"],
    masteryRate: 68,
  },
];

/** 班级学情分析 mock */
export const mockClassAnalytics: ClassAnalytics = {
  classId: "550e8400-e29b-41d4-a716-446655440010",
  className: "高三(1)班",
  avgScore: 78.5,
  passRate: 87.5,
  avgTrend: [72, 74, 76, 77, 79],
  topStudents,
  weakPoints: ["导数", "函数", "书面表达", "阅读理解"],
};

/** 单生学情分析 mock（默认返回 Top1 学生数据） */
export const mockStudentAnalytics: StudentAnalytics = {
  studentId: "stu-001",
  studentName: "学生01",
  avgScore: 92,
  trend: [88, 90, 85, 91, 94],
  weakPoints: ["导数", "书面表达"],
  strongPoints: ["实数与运算", "词汇基础"],
  masteryRate: 90,
};

/**
 * 按学生 ID 查找学情数据
 * 未命中时返回 mockStudentAnalytics 兜底
 */
export function findStudentAnalytics(
  studentId: string,
): StudentAnalytics {
  const found = topStudents.find((s) => s.studentId === studentId);
  if (found) {
    return found;
  }
  // 未命中时基于 studentId 构造一份变化数据，避免页面空态
  return {
    ...mockStudentAnalytics,
    studentId,
    studentName: `学生${studentId.slice(-2)}`,
    avgScore: 75,
    trend: [70, 72, 74, 73, 76],
    weakPoints: ["函数", "现代文阅读"],
    strongPoints: ["词汇基础"],
    masteryRate: 65,
  };
}
