package com.qmth.distributed.print.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.service.ConditionService;
import com.qmth.teachcloud.common.bean.result.BasicCollegeResult;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.*;
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 java.util.List;

/**
 * 查询条件
 */
@Api(tags = "查询条件Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_BASIC + "/condition")
public class ConditionController {
    @Resource
    private ConditionService conditionService;

    @ApiOperation(value = "学期")
    @RequestMapping(value = "/list_semester", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = BasicCollegeResult.class)})
    public Result listSemester(@ApiParam(value = "启用/禁用") @RequestParam(required = false, defaultValue = "true") Boolean enable) {
        return ResultUtil.ok(conditionService.listSemester(enable));
    }

    @ApiOperation(value = "考试")
    @RequestMapping(value = "/list_exam", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = BasicCollegeResult.class)})
    public Result listExam(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId,
                           @ApiParam(value = "启用/禁用") @RequestParam(required = false, defaultValue = "true") Boolean enable) {
        return ResultUtil.ok(conditionService.listExam(semesterId, enable));
    }

    @ApiOperation(value = "课程")
    @RequestMapping(value = "/list_course", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = BasicCollegeResult.class)})
    public Result listCourse(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId,
                             @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
                             @ApiParam(value = "启用/禁用") @RequestParam(required = false) Boolean enable,
                             @RequestParam(value = "printPlanId", required = false) List<String> printPlanId) {
        return ResultUtil.ok(conditionService.listCourse(semesterId, examId, enable, printPlanId));
    }

    @ApiOperation(value = "试卷编号")
    @RequestMapping(value = "/list_paper_number", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = BasicCollegeResult.class)})
    public Result listPaperNumber(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId,
                                  @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
                                  @ApiParam(value = "课程代码") @RequestParam(required = false) String courseCode,
                                  @RequestParam(value = "printPlanId", required = false) List<String> printPlanId) {
        return ResultUtil.ok(conditionService.listPaperNumber(semesterId, examId, courseCode, printPlanId));
    }

    @ApiOperation(value = "印刷计划")
    @RequestMapping(value = "/list_print_plan", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = BasicCollegeResult.class)})
    public Result listPrintPlan(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId,
                                @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
                                @ApiParam(value = "source") @RequestParam(required = false) String source) {
        return ResultUtil.ok(conditionService.listPrintPlan(semesterId, examId, source));
    }

    @ApiOperation(value = "试卷编号")
    @RequestMapping(value = "/list_clazz", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = BasicCollegeResult.class)})
    public Result listClazz(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId,
                                  @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
                                  @ApiParam(value = "课程代码") @RequestParam(required = false) String courseCode) {
        return ResultUtil.ok(conditionService.listClazz(semesterId, examId, courseCode));
    }
}
