package com.ruoyi.web.controller.exam;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.paper.dto.request.PaperAnswerDTO;
import com.ruoyi.system.domain.paper.dto.request.PaperQuQueryDTO;
import com.ruoyi.web.controller.manager.PaperManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * packageName com.ruoyi.web.controller.examination
 *
 * @author wangxy
 * @version JDK 8
 * @className PaperController
 * @date 2024/6/28
 * @description 试卷
 */
@Api("在线考试")
@Controller
@RequestMapping("/system/paper")
public class PaperController extends BaseController {


    @Resource
    private PaperManager paperManager;


    @ApiOperation("创建试卷")
    @Log(title = "创建试卷", businessType = BusinessType.INSERT)
    @GetMapping("/create/{examId}")
    @ResponseBody
    public AjaxResult create(@PathVariable("examId") String examId) {
        return AjaxResult.success(paperManager.createPaper(examId,getUserId()));
    }

    @ApiOperation("试卷详情")
    @GetMapping("/detail/{paperId}")
    @ResponseBody
    public AjaxResult detail(@PathVariable("paperId") String paperId) {
        return AjaxResult.success(paperManager.paperDetail(paperId));
    }

    @ApiOperation("试题详情")
    @PostMapping("/quDetail")
    @ResponseBody
    public AjaxResult quDetail(@Validated PaperQuQueryDTO reqDTO) {
        return AjaxResult.success(paperManager.findQuDetail(reqDTO.getPaperId(), reqDTO.getQuId()));
    }

    @ApiOperation("保存答案")
    @PostMapping("/fillAnswer")
    @ResponseBody
    public AjaxResult fillAnswer(@Validated PaperAnswerDTO reqDTO) {
        return toAjax(paperManager.fillAnswer(reqDTO));
    }


    @ApiOperation("交卷")
    @GetMapping("/submitExam/{paperId}")
    @Log(title = "交卷", businessType = BusinessType.INSERT)
    @ResponseBody
    public AjaxResult submitExam(@PathVariable("paperId") String paperId) {
        return toAjax(paperManager.submitExam(paperId));
    }







}
