package com.ningdatech.carapi.industry.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.industry.manage.PassportManage;
import com.ningdatech.carapi.industry.model.dto.PassportPageParamDTO;
import com.ningdatech.carapi.industry.model.dto.PassportSaveDTO;
import com.ningdatech.carapi.industry.model.dto.PassportUpdateDTO;
import com.ningdatech.carapi.industry.model.vo.PassportVO;
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;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 通行证管理 前端控制器
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-11-05
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/industry/passport")
@Api(value = "PassportManage", tags = "行业服务-通行证管理")
@RequiredArgsConstructor
public class PassportManageController {

    private final PassportManage passportManage;

    @ApiOperation(value = "通行证证书信息", notes = "通行证证书信息")
    @GetMapping("/info-list")
    public PageVo<PassportVO> infoList(@Valid @ModelAttribute PassportPageParamDTO param) {
        return passportManage.infoList(param);
    }

    @ApiOperation(value = "通行证证书详情", notes = "通行证证书详情")
    @GetMapping("/details/{id}")
    public PassportVO details(@Valid @PathVariable Long id) {
        return passportManage.details(id);
    }

    @ApiOperation(value = "通行证申请列表", notes = "通行证申请列表")
    @GetMapping("/application-list")
    public PageVo<PassportVO> applicationList(@Valid @ModelAttribute PassportPageParamDTO param) {
        return passportManage.infoList(param);
    }

    @ApiOperation(value = "通行证审核列表", notes = "通行证审核列表")
    @GetMapping("/approve-list")
    public PageVo<PassportVO> approveList(@Valid @ModelAttribute PassportPageParamDTO param) {
        return passportManage.infoList(param);
    }

    @ApiOperation(value = "通行证补发列表", notes = "通行证补发列表")
    @GetMapping("/reissue-list")
    public PageVo<PassportVO> reissueList(@Valid @ModelAttribute PassportPageParamDTO param) {
        return passportManage.infoList(param);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public PassportVO save(@Valid @RequestBody PassportSaveDTO passportSave) {
        return passportManage.save(passportSave, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "编辑", notes = "编辑")
    @PostMapping("/modify")
    public PassportVO modify(@Valid @RequestBody PassportUpdateDTO passportUpdate) {
        return passportManage.modify(passportUpdate, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove/{id}")
    public Boolean remove(@Valid @PathVariable Long id) {
        return passportManage.remove(id, LoginUserUtil.getUserId());
    }

    @ApiOperation("通行证证书信息列表导出")
    @GetMapping("/infoListExport")
    public void infoListExport(PassportPageParamDTO param, HttpServletResponse response){
        ExcelDownUtil.downXls(response, param, passportManage::infoListExport);
    }
}
