/**
 * 统计分析API
 */
import request from './request'

/**
 * 统计参数接口
 */
export interface StatisticsParams {
  course_id?: number  // 课程ID，不传则统计全部课程
  period?: string     // 时间范围: week/month/quarter/halfYear/year
}

/**
 * 关键指标响应接口
 */
export interface KeyMetricsResponse {
  learningEfficiency: {
    value: number
    unit: string
    change: number
    description: string
  }
  knowledgeCoverage: {
    value: number
    unit: string
    change: number
    description: string
  }
  avgTimePerQuestion: {
    value: number
    unit: string
    change: number
    description: string
  }
  progressSpeed: {
    value: number
    unit: string
    change: number
    description: string
  }
}

/**
 * 成绩分布响应接口
 */
export interface ScoreDistributionResponse {
  excellent: number  // 优秀(90-100)
  good: number      // 良好(80-89)
  medium: number    // 中等(70-79)
  pass: number      // 及格(60-69)
  fail: number      // 不及格(<60)
}

/**
 * 难度分析响应接口
 */
export interface DifficultyAnalysisResponse {
  简单题: number
  中等题: number
  困难题: number
  综合题: number
  应用题: number
}

/**
 * 知识点掌握度响应接口
 */
export interface KnowledgeMasteryItem {
  name: string
  mastery: number
}

/**
 * 学习时长统计响应接口
 */
export interface StudyTimeStatsResponse {
  labels: string[]
  studyTime: number[]
  practiceTime: number[]
}

/**
 * 详细数据响应接口
 */
export interface DetailDataItem {
  date: string
  examCount: number
  avgScore: number
  studyTime: number
  questionCount: number
  accuracy: number
  improvement: number
}

/**
 * 获取关键指标
 */
export const getKeyMetrics = (params: StatisticsParams = {}) => {
  return request.get<KeyMetricsResponse>('/api/v1/statistics/key-metrics', params)
}

/**
 * 获取成绩分布
 */
export const getScoreDistribution = (params: StatisticsParams = {}) => {
  return request.get<ScoreDistributionResponse>('/api/v1/statistics/score-distribution', params)
}

/**
 * 获取难度分析
 */
export const getDifficultyAnalysis = (params: StatisticsParams = {}) => {
  return request.get<DifficultyAnalysisResponse>('/api/v1/statistics/difficulty-analysis', params)
}

/**
 * 获取知识点掌握度
 */
export const getKnowledgeMastery = (params: { course_id?: number } = {}) => {
  return request.get<KnowledgeMasteryItem[]>('/api/v1/statistics/knowledge-mastery', params)
}

/**
 * 获取学习时长统计
 */
export const getStudyTimeStats = (params: StatisticsParams = {}) => {
  return request.get<StudyTimeStatsResponse>('/api/v1/statistics/study-time', params)
}

/**
 * 获取详细数据
 */
export const getDetailData = (params: StatisticsParams = {}) => {
  return request.get<DetailDataItem[]>('/api/v1/statistics/detail', params)
}

