package com.ningdatech.carapi.driver.controller;


import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.driver.manage.TrainingOrganizationManage;
import com.ningdatech.carapi.driver.model.po.*;
import com.ningdatech.carapi.driver.model.query.TrainingOrgTrainersQuery;
import com.ningdatech.carapi.driver.model.vo.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LiuXinXin
 * @since 2022-10-10
 */
@RequestMapping("/api/v1/driver/training-organization")
@RestController
@Api(tags = "驾驶员管理-培训管理-培训组织")
@Validated
@RequiredArgsConstructor
public class TrainingOrganizationController {

    private final TrainingOrganizationManage trainingOrganizationManage;

    @PostMapping("/save")
    @ApiOperation("保存培训组织(新接口)")
    public ResCreateTrainingOrgVO saveTrainingOrganization(@Valid @RequestBody ReqCreateTrainingOrgPO request) {
        return trainingOrganizationManage.saveTrainingOrganization(request);
    }

    @PostMapping("/list")
    @ApiOperation("培训组织-列表查询(新接口)")
    public PageVo<ResTrainingOrganizationListVO> trainingOrganizationList(@Valid @RequestBody ReqTrainingOrganizationListPO request) {
        return trainingOrganizationManage.trainingOrganizationList(request);
    }

    @PostMapping("/status-modify")
    @ApiOperation("培训组织状态变更")
    public void trainingOrganizationStatusModify(@Valid @RequestBody ReqTrainingOrganizationStatusModifyPO request) {
        trainingOrganizationManage.trainingOrganizationStatusModify(request);
    }

    @PostMapping("/detail/{organizationId}")
    @ApiOperation("培训组织-详情")
    public ResTrainingOrganizationDetailVO trainingOrganizationDetail(@Valid @PathVariable("organizationId") Long organizationId) {
        return trainingOrganizationManage.trainingOrganizationDetail(organizationId);
    }

    @PostMapping("/delete/{organizationId}")
    @ApiOperation("培训组织-删除培训组织")
    public void deleteTrainingOrganization(@Valid @PathVariable("organizationId") Long organizationId) {
        trainingOrganizationManage.deleteTrainingOrganization(organizationId);
    }

    @PostMapping("/upload/exam-result")
    @ApiOperation("培训考试-上传考试结果")
    public void uploadExamResult(@Valid @RequestBody ReqUploadExamResultPO request) {
        trainingOrganizationManage.uploadExamResult(request);
    }

    @PostMapping("/upload/exam-result-generate-certificate")
    @ApiOperation("培训考试-上传考试结果并生成电子合格证")
    public void uploadExamResultAndGenerateCertificate(@Valid @RequestBody ReqUploadExamResultPO request) {
        trainingOrganizationManage.uploadExamResultAndGenerateCertificate(request);
    }

    @PostMapping("/make-up-exam")
    @ApiOperation("补考")
    public void makeUpExam(@Valid @RequestBody ReqMakeUpExamPO request) {
        trainingOrganizationManage.makeUpExam(request);
    }

    @PostMapping("/get/current-user-organization")
    @ApiOperation("获取当前用户培训组织")
    public ResCurrentUserOrganizationVO getCurrentUserOrganization(@Valid @RequestBody ReqCurrentUserOrganizationPO request) {
        return trainingOrganizationManage.getCurrentUserOrganization(request);
    }

    @PostMapping("/sign/{organizationId}")
    @ApiOperation("培训签到")
    public void organizationSign(@PathVariable("organizationId") Long organizationId) {
        trainingOrganizationManage.organizationSign(organizationId);
    }

    @PostMapping("/sign/check/{organizationId}")
    @ApiOperation("培训签到校验 已签到返回 true 否则返回false")
    public Boolean organizationSignCheck(@PathVariable("organizationId") Long organizationId) {
        return trainingOrganizationManage.organizationSignCheck(organizationId);
    }

    @PostMapping("/driver-training/list")
    @ApiOperation("驾驶员培训记录列表")
    public PageVo<ResDriverTrainingListVO> driverTrainingList(@Valid @RequestBody ReqDriverTrainingListPO request) {
        return trainingOrganizationManage.driverTrainingList(request);
    }

    @GetMapping("/getTrainers")
    @ApiOperation("获取培训组织关联的培训人员信息")
    public PageVo<ResTrainingOrgTrainerVO> trainerList(@Valid @ModelAttribute TrainingOrgTrainersQuery request){
        return trainingOrganizationManage.trainerList(request);
    }

    @PostMapping("/set/exam-time")
    @ApiOperation("培训考试-设置考试时间")
    public String setExamTime(@Valid @RequestBody ReqSetExamTimePO request) {
        return trainingOrganizationManage.setExamTime(request);
    }

    @PostMapping("/trainer/export")
    @ApiOperation("培训人员信息导出")
    public void exportTrainer(@Valid @ModelAttribute ReqTrainerExportPO req, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, req, trainingOrganizationManage::exportTrainer);
    }
}
