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.AnnualInspectionReviewManage;
import com.ningdatech.carapi.industry.model.dto.InspectionReviewSaveDTO;
import com.ningdatech.carapi.industry.model.dto.InspectionReviewUpdateDTO;
import com.ningdatech.carapi.industry.model.dto.ReviewPageParamDTO;
import com.ningdatech.carapi.industry.model.vo.VehicleAnnualInspectionReviewApplicationVO;
import com.ningdatech.carapi.industry.model.vo.VehicleAnnualInspectionReviewVO;
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.stereotype.Controller;
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
 */
@Controller
@RequestMapping("/api/industry/vehicle-annual-inspection-review")
@Slf4j
@Validated
@RestController
@Api(value = "VehicleAnnualInspectionReview", tags = "行业服务-车辆年检年审")
@RequiredArgsConstructor
public class VehicleAnnualInspectionReviewController {

    private final AnnualInspectionReviewManage annualInspectionReviewManage;

    @ApiOperation(value = "年检年审记录", notes = "年检年审记录")
    @GetMapping("/info-list")
    public PageVo<VehicleAnnualInspectionReviewVO> infoList(@Valid @ModelAttribute ReviewPageParamDTO param) {
        return annualInspectionReviewManage.infoList(param);
    }

    @ApiOperation(value = "年检年审记录详情", notes = "年检年审记录详情")
    @GetMapping("/details/{id}")
    public VehicleAnnualInspectionReviewVO details(@Valid @PathVariable Long id) {
        return annualInspectionReviewManage.details(id);
    }

    @ApiOperation(value = "年检年审记录申请", notes = "年检年审记录申请")
    @GetMapping("/application-list")
    public PageVo<VehicleAnnualInspectionReviewApplicationVO> applicationList(@Valid @ModelAttribute ReviewPageParamDTO param) {
        return annualInspectionReviewManage.applicationList(param);
    }

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

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

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

    @ApiOperation("车辆年检年审记录列表导出")
    @GetMapping("/infoListExport")
    public void infoListExport(ReviewPageParamDTO param, HttpServletResponse response){
        ExcelDownUtil.downXls(response, param, annualInspectionReviewManage::infoListExport);
    }
}
