// Learning Diagnostic Module Types

export type DiagnosticReportType = "individual" | "class" | "grade"
export type DiagnosticReportStatus = "draft" | "published" | "archived"

/** 知识点掌握度记录 */
export interface KnowledgePointMastery {
  id: string
  studentId: string
  knowledgePointId: string
  masteryLevel: number // 0-100
  totalQuestions: number
  correctQuestions: number
  lastAssessedAt: string
  createdAt: string
  updatedAt: string
}

/** 含知识点名称的掌握度（join knowledgePoints 后） */
export interface MasteryWithKnowledgePoint extends KnowledgePointMastery {
  knowledgePointName: string
  knowledgePointDescription: string | null
}

/** 学生掌握度摘要 */
export interface StudentMasterySummary {
  studentId: string
  studentName: string
  averageMastery: number
  totalKnowledgePoints: number
  strengths: MasteryWithKnowledgePoint[] // 掌握度 >= 80
  weaknesses: MasteryWithKnowledgePoint[] // 掌握度 < 80（P3-16 修复：消除 60-79 盲区）
  allMastery: MasteryWithKnowledgePoint[]
}

/** 诊断报告 */
export interface DiagnosticReport {
  id: string
  studentId: string | null
  /** v4-P1-4: 班级报告关联的 classId（个人报告为 null） */
  classId: string | null
  /** v4-P2-3: 年级报告关联的 gradeId（个人/班级报告为 null） */
  gradeId: string | null
  generatedBy: string | null
  reportType: DiagnosticReportType
  period: string | null
  summary: string | null
  strengths: string[] | null
  weaknesses: string[] | null
  recommendations: string[] | null
  overallScore: number | null
  status: DiagnosticReportStatus
  createdAt: string
  updatedAt: string
}

/** 含学生名的诊断报告（join users 后） */
export interface DiagnosticReportWithDetails extends DiagnosticReport {
  studentName: string | null
  generatedByName: string | null
}

/** 班级掌握度摘要 */
export interface ClassMasterySummary {
  classId: string
  className: string
  studentCount: number
  averageMastery: number
  knowledgePointStats: KnowledgePointStat[]
  studentsNeedingAttention: Array<{
    studentId: string
    studentName: string
    averageMastery: number
    weakCount: number
  }>
}

/** v4-P2-3: 年级掌握度摘要（结构同 ClassMasterySummary，但标识为年级） */
export interface GradeMasterySummary {
  gradeId: string
  gradeName: string
  studentCount: number
  averageMastery: number
  knowledgePointStats: KnowledgePointStat[]
  studentsNeedingAttention: Array<{
    studentId: string
    studentName: string
    averageMastery: number
    weakCount: number
  }>
}

/** 知识点统计 */
export interface KnowledgePointStat {
  knowledgePointId: string
  knowledgePointName: string
  averageMastery: number
  masteredCount: number // 掌握度 >= 80
  notMasteredCount: number // 掌握度 < 60
  totalStudents: number
}

/** 报告查询过滤参数 */
export interface DiagnosticReportQueryParams {
  studentId?: string
  reportType?: DiagnosticReportType
  status?: DiagnosticReportStatus
  period?: string
  /** 分页：每页数量（默认 100） */
  limit?: number
  /** 分页：偏移量（默认 0） */
  offset?: number
}

/** 分页查询诊断报告结果（P3-15 修复：支持分页） */
export interface DiagnosticReportListResult {
  reports: DiagnosticReportWithDetails[]
  total: number
}

/** 雷达图数据点 */
export interface MasteryRadarPoint {
  knowledgePoint: string
  student: number // 0-100
  classAverage?: number // 0-100
}
