/**
 * Mock 成绩数据（core-edu 域）
 *
 * 维护者：ai13（teacher-portal）
 */

import type { GradeItem, RecordGradeInput } from "@/lib/graphql";

export function generateMockGrades(examId: string): GradeItem[] {
  const grades: GradeItem[] = [];
  for (let i = 1; i <= 30; i++) {
    const score = Math.floor(Math.random() * 40) + 60;
    const feedback =
      score < 70 ? "需要加强基础练习" : score > 90 ? "表现出色" : null;
    grades.push({
      id: `${examId}-grade-${i}`,
      studentId: `${examId.slice(0, -3)}${String(i).padStart(3, "0")}`,
      studentName: `学生${String(i).padStart(2, "0")}`,
      examId,
      homeworkId: null,
      score,
      feedback,
    });
  }
  return grades;
}

/** 录入成绩：基于 input 生成 GradeItem（含随机 ID + 学生名兜底） */
export function recordMockGrade(input: RecordGradeInput): GradeItem {
  const randomId = Math.random().toString(36).slice(2, 10);
  const idx = Math.floor(Math.random() * 30) + 1;
  return {
    id: `grade-${randomId}`,
    studentId: input.studentId,
    studentName: `学生${String(idx).padStart(2, "0")}`,
    examId: input.examId ?? null,
    homeworkId: input.homeworkId ?? null,
    score: input.score,
    feedback: input.feedback ?? null,
  };
}
