package com.ningdatech.carapi.safe.controller;

import java.io.FileNotFoundException;

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

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.safe.manage.VehicleInsureManage;
import com.ningdatech.carapi.safe.model.dto.InsurePageQuery;
import com.ningdatech.carapi.safe.model.vo.NdInsureInfoVO;
import com.ningdatech.carapi.safe.model.vo.NdInsureOutDangerAnalysisVO;
import com.ningdatech.carapi.safe.model.vo.NdInsureOutDangerVO;

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

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-10-12
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/safe/insure")
@Api(value = "Insure", tags = "安全管理-保险管理")
@RequiredArgsConstructor
public class NdVehicleInsureController {

    private final VehicleInsureManage vehicleInsureManage;

    @ApiOperation(value = "承保信息", notes = "承保信息")
    @GetMapping("/underwriting")
    public PageVo<NdInsureInfoVO> queryVehicle(@Valid @ModelAttribute InsurePageQuery insurePageQuery) {
        return vehicleInsureManage.queryVehicleInsure(insurePageQuery);
    }

    @ApiOperation(value = "出险信息", notes = "出险信息")
    @GetMapping("/outDanger")
    public PageVo<NdInsureOutDangerVO> queryOutDanger(@Valid @ModelAttribute InsurePageQuery insurePageQuery) {
        return vehicleInsureManage.queryOutDanger(insurePageQuery);
    }

    @ApiOperation(value = "出险分析", notes = "出险分析")
    @GetMapping("/analysis")
    public PageVo<NdInsureOutDangerAnalysisVO> queryInsureOutDangerAnalysis(@Valid @ModelAttribute InsurePageQuery insurePageQuery) {
        return vehicleInsureManage.queryInsureOutDangerAnalysis(insurePageQuery);
    }

    @GetMapping("/exportOutDanger")
    @ApiOperation("导出出险信息")
    public void export(InsurePageQuery req, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, req, vehicleInsureManage::exportOutDanger);
    }


    @GetMapping("/importOutDanger")
    @ApiOperation("手动导入出险信息")
    public void importOutDanger() throws FileNotFoundException {
        vehicleInsureManage.importOutDanger();
    }


}
