package com.ningdatech.carapi.industry.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.industry.contants.CertificateContant;
import com.ningdatech.carapi.industry.manage.DriverTrainingCertificateManage;
import com.ningdatech.carapi.industry.model.dto.DriverTrainingCertificatePageParamDTO;
import com.ningdatech.carapi.industry.model.dto.DriverTrainingCertificateUpdateDTO;
import com.ningdatech.carapi.industry.model.vo.DriverTrainingCertificateOperVO;
import com.ningdatech.carapi.industry.model.vo.DriverTrainingCertificateVO;
import com.ningdatech.carapi.user.util.LoginUserUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 驾驶员合格证 前端控制器
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-11-03
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/industry/driver-training-certificate")
@Api(value = "DriverTrainingCertificate", tags = "行业服务-驾驶员培训合格证")
@RequiredArgsConstructor
public class DriverTrainingCertificateController {

    private final DriverTrainingCertificateManage driverTrainingCertificateManage;

    @ApiOperation(value = "合格证信息列表", notes = "合格证信息列表")
    @GetMapping("/info-list")
    public PageVo<DriverTrainingCertificateVO> infoList(@Valid @ModelAttribute DriverTrainingCertificatePageParamDTO param) {
        return driverTrainingCertificateManage.infoList(param);
    }

    @ApiOperation(value = "合格证信息详情", notes = "合格证信息详情")
    @GetMapping("/info-details/{id}")
    public DriverTrainingCertificateVO infoDetails(@Valid @PathVariable Long id) {
        return driverTrainingCertificateManage.infoDetails(id);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public Long save(@Valid @RequestBody DriverTrainingCertificateUpdateDTO data) {
        return driverTrainingCertificateManage.save(data, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "编辑", notes = "编辑")
    @PostMapping("/modify")
    public DriverTrainingCertificateVO modify(@Valid @RequestBody DriverTrainingCertificateUpdateDTO data) {
        return driverTrainingCertificateManage.modify(data, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "合格证申请列表", notes = "合格证申请列表")
    @GetMapping("/application-list")
    public PageVo<DriverTrainingCertificateOperVO> applicationList(@Valid @ModelAttribute DriverTrainingCertificatePageParamDTO param) {
        return driverTrainingCertificateManage.operationList(param, CertificateContant.OPERATION_TYPE_APPCATION);
    }

    @ApiOperation(value = "合格证补发列表", notes = "合格证补发列表")
    @GetMapping("/reissue-list")
    public PageVo<DriverTrainingCertificateOperVO> reissueList(@Valid @ModelAttribute DriverTrainingCertificatePageParamDTO param) {
        return driverTrainingCertificateManage.operationList(param, CertificateContant.OPERATION_TYPE_REISSUE);
    }

    @ApiOperation(value = "审核", notes = "审核")
    @RequestMapping("/approve/{id}")
    public DriverTrainingCertificateOperVO approve(@Valid @PathVariable Long id) {
        return driverTrainingCertificateManage.approve(id, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "取消审核", notes = "取消审核")
    @RequestMapping("/unapprove/{id}")
    public DriverTrainingCertificateOperVO unapprove(@Valid @PathVariable Long id) {
        return driverTrainingCertificateManage.unapprove(id, LoginUserUtil.getUserId());
    }

    @ApiOperation("驾驶员培训合格证书信息列表导出")
    @GetMapping("/infoListExport")
    public void infoListExport(DriverTrainingCertificatePageParamDTO param,HttpServletResponse response){
        ExcelDownUtil.downXls(response, param, driverTrainingCertificateManage::infoListExport);
    }
}
