package cn.iocoder.yudao.module.exam.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.exam.service.ExamBatchService;
import cn.iocoder.yudao.module.exam.vo.ExamBatchItemNewVO;
import cn.iocoder.yudao.module.exam.vo.ExamBatchNewVO;
import cn.iocoder.yudao.module.exam.vo.ExamBatchVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 考试批次")
@RestController
@RequestMapping("/examBatch")
@Validated
public class ExamBatchController {

    @Resource
    private ExamBatchService examBatchService;


    @GetMapping("/page")
    @Operation(summary = "获得考试批次分页")
    public CommonResult<IPage<?>> getPage(ExamBatchVO pageReqVO,
                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<ExamBatchVO> page = new Page<>(pageNo,pageSize);
        return success(examBatchService.queryListPage(pageReqVO,page));
    }

    @GetMapping("/newPage")
    public CommonResult<IPage<?>> getPageNew(ExamBatchVO pageReqVO,
                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<ExamBatchItemNewVO> page = new Page<>(pageNo,pageSize);
        return success(examBatchService.queryListPageNew(pageReqVO,page));
    }

    @PostMapping("/create")
    @Operation(summary = "送考")
    public CommonResult<?> createObj( @RequestBody ExamBatchVO examBatchVO) {
        examBatchService.createObj(examBatchVO);
        return success(true);
    }

    @GetMapping("/getById")
    @Operation(summary = "查某一批次详情")
    public CommonResult<?> getById(String id) {
        return success(examBatchService.selectOneById(id));
    }

    /**
     * 某一教练学员通过和未通过列表
     */
    @GetMapping("/getStudentByCoachId")
    public CommonResult<?> getStudentByCoachId(@RequestParam("subject") int subject,
                                               @RequestParam(name ="coachId", required = false) Long coachId,
                                               @RequestParam(name = "ifPass", required = false) String ifPass,
                                               @RequestParam(name = "name", required = false) String name,
                                               @RequestParam(name = "sort", required = false) String sort,
                                               @RequestParam(name = "timeType", required = false) String timeType,
                                               @RequestParam(name = "startTime", required = false) String startTime,
                                               @RequestParam(name = "endTime", required = false) String endTime,
                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<ExamBatchNewVO> page = new Page<>(pageNo,pageSize);
        return success(examBatchService.getStudentByCoachId(subject, coachId, ifPass, name, sort, timeType, startTime, endTime, page));
     }

}
