package com.qmth.distributed.print.api.mark;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
import com.qmth.teachcloud.common.enums.log.OperationTypeEnum;
import com.qmth.teachcloud.mark.dto.mark.manage.MarkProblemDto;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.mark.service.MarkProblemHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

/**
 * <p>
 * 问题卷 前端控制器
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Api(tags = "评卷-问题卷")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_MARK + "/problem")
public class MarkProblemController {

    @Resource
    private MarkProblemHistoryService markProblemHistoryService;

    /**
     * 问题卷列表
     */
    @ApiOperation(value = "问题卷列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                       @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
                       @ApiParam(value = "分组号") @RequestParam(required = false) Integer groupNumber,
                       @ApiParam(value = "问题类型") @RequestParam(required = false) String problemType,
                       @ApiParam(value = "状态") @RequestParam(required = false) String status,
                       @ApiParam(value = "密号") @RequestParam(required = false) String secretNumber,
                       @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                       @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        IPage<MarkProblemDto> markProblemDtoIPage = markProblemHistoryService.pageProblem(examId, paperNumber, groupNumber, problemType, status, secretNumber, pageNumber, pageSize);
        return ResultUtil.ok(markProblemDtoIPage);
    }

    /**
     * 重置
     */
    @ApiOperation(value = "重置")
    @RequestMapping(value = "/reset", method = RequestMethod.POST)
    @OperationLogDetail(operationType = OperationTypeEnum.UPDATE, detail = "问题卷重置操作，问题卷任务ID集合：{{ids}}")
    public Result reset(@ApiParam(value = "问题卷任务ID集合", required = true) @RequestParam List<Long> ids) {
        markProblemHistoryService.resetProblem(ids);
        return ResultUtil.ok(true);
    }
}
