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.ExamMarkForm;
import cn.reghao.tnb.content.app.exam.model.query.ExamQuery;
import cn.reghao.tnb.content.app.exam.model.vo.ExamMark;
import cn.reghao.tnb.content.app.exam.model.vo.ExamResult;
import cn.reghao.tnb.content.app.exam.model.vo.ExamScore;
import cn.reghao.tnb.content.app.exam.service.ExamResultService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2024-08-29 09:54:34
 */
@Tag(name = "考试结果接口")
@RestController
@RequestMapping("/api/content/exam/result")
public class ExamResultController {
    private final ExamResultService examResultService;

    public ExamResultController(ExamResultService examResultService) {
        this.examResultService = examResultService;
    }

    @Operation(summary = "获取试卷结果", description = "N")
    @GetMapping(value = "/mark", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getExamMark(ExamQuery examQuery) {
        PageList<ExamMark> pageList = examResultService.getExamReviewList(examQuery);
        return WebResult.success(pageList);
    }

    @Operation(summary = "提交评卷结果", description = "N")
    @PostMapping(value = "/mark", produces = MediaType.APPLICATION_JSON_VALUE)
    public String submitExamMark(@RequestBody @Validated ExamMarkForm examMarkForm) {
        examResultService.markExamResult(examMarkForm);
        return WebResult.success();
    }

    @Operation(summary = "获取用户的考试成绩", description = "N")
    @GetMapping(value = "/score", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getExamScore() {
        PageList<ExamScore> pageList = examResultService.getExamScoreList();
        return WebResult.success(pageList);
    }

    @Operation(summary = "获取用户的考试结果", description = "N")
    @GetMapping(value = "/view/{resultId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getExamResult(@PathVariable("resultId") int resultId) {
        ExamResult examResult = examResultService.getExamResult(resultId);
        return WebResult.success(examResult);
    }
}
