package com.sundot.airport.web.controller.exam;

import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.dto.QuizAccuracyAnalysisResultDto;
import com.sundot.airport.exam.service.IAccuracyStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 抽问抽答正确率分析接口
 */
@RestController
@RequestMapping("/exam/quiz/accuracy-analysis")
public class QuizAccuracyAnalysisController {

    @Autowired
    private IAccuracyStatisticsService accuracyStatisticsService;

    /**
     * 获取抽问抽答正确率分析
     * 返回全站平均正确率、各题目分类正确率，并标注最高/薄弱分类
     *
     * @param startDate 开始日期（yyyy-MM-dd）
     * @param endDate   结束日期（yyyy-MM-dd）
     * @return 正确率分析结果
     */
    @GetMapping
    public AjaxResult getQuizAccuracyAnalysis(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        QuizAccuracyAnalysisResultDto result = accuracyStatisticsService.getQuizAccuracyAnalysis(
                sdf.format(startDate), sdf.format(endDate));
        return AjaxResult.success(result);
    }
}
