package cn.reghao.tnb.content.app.exam.controller;

import cn.reghao.jutil.jdk.db.PageList;
import cn.reghao.jutil.web.WebResult;
import cn.reghao.tnb.content.app.exam.model.dto.UserResult;
import cn.reghao.tnb.content.app.exam.model.query.PaperQuery;
import cn.reghao.tnb.content.app.exam.model.vo.*;
import cn.reghao.tnb.content.app.exam.service.ExamService;
import cn.reghao.tnb.content.app.exam.service.PaperService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2024-08-24 13:29:10
 */
@Tag(name = "考试接口")
@RestController
@RequestMapping("/api/content/exam")
public class ExamController {
    private final ExamService examService;
    private final PaperService paperService;

    public ExamController(ExamService examService, PaperService paperService) {
        this.examService = examService;
        this.paperService = paperService;
    }

    @Operation(summary = "获取考试列表", description = "N")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    @Deprecated
    public String getExams(PaperQuery paperQuery) {
        PageList<PaperView> pageList1 = paperService.getExamPapers(paperQuery);
        return WebResult.success(pageList1);
    }

    @Operation(summary = "获取考试使用的试卷", description = "N")
    @GetMapping(value = "/start/{paperId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @Deprecated
    public String startExam(@PathVariable("paperId") int paperId) {
        return WebResult.success();
    }

    @Operation(summary = "获取试卷中的试题", description = "N")
    @GetMapping(value = "/paper/{paperId}/question", produces = MediaType.APPLICATION_JSON_VALUE)
    @Deprecated
    public String getExamQuestions1(@PathVariable("paperId") Integer paperId) {
        List<QuestionInfo> list1 = paperService.getPaperQuestions(paperId);
        return WebResult.success(list1);
    }

    @Operation(summary = "用户提交考试答案", description = "N")
    @PostMapping(value = "/submit", produces = MediaType.APPLICATION_JSON_VALUE)
    public String submitExamPaper1(@RequestBody UserResult userResult) {
        int resultId = examService.submitExamPaper(userResult);
        return WebResult.success(resultId);
    }
}
