package com.ningdatech.carapi.analysis.controller;

import com.ningdatech.carapi.analysis.entity.enumeration.DangerLevel;
import com.ningdatech.carapi.analysis.entity.vo.CompanyWarnStatisticsVo;
import com.ningdatech.carapi.analysis.manage.AnalysisEvalDataViewManage;
import com.ningdatech.carapi.common.model.DataChartVo;
import com.ningdatech.carapi.common.model.MapDataVO;
import com.ningdatech.carapi.common.util.CodeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * AnalysisEvalDataViewController
 * </p>
 *
 * @author WendyYang
 * @since 15:24 2022/10/25
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "分析评估-数据大屏")
@RequestMapping("/api/v1/analysis-eval/data-view")
public class AnalysisEvalDataViewController {

    private final AnalysisEvalDataViewManage analysisEvalDataViewManage;

    @GetMapping("/insuranceOrgStatistics/{regionId}")
    @ApiOperation("保险机构车辆占比")
    public List<DataChartVo> insuranceOrgStatistics(@PathVariable Long regionId) {
        regionId = CodeUtil.convertRegionCodeToId(regionId);
        return analysisEvalDataViewManage.insuranceOrgStatistics(regionId);
    }

    @GetMapping("/companyWarnStatistics/{regionId}")
    @ApiOperation("企业综合预警分析")
    public List<CompanyWarnStatisticsVo> companyWarnStatistics(@PathVariable Long regionId) {
        regionId = CodeUtil.convertRegionCodeToId(regionId);
        return analysisEvalDataViewManage.companyWarnStatistics(regionId);
    }

    @GetMapping("/companyWarnStatisticsByLevel")
    @ApiOperation("企业红色预警")
    public List<DataChartVo> companyWarnStatisticsByLevel(@RequestParam("regionId") Long regionId,
                                                          @RequestParam(value = "dangerLevel", required = false) Integer dangerLevel) {
        regionId = CodeUtil.convertRegionCodeToId(regionId);
        // 默认查询最低等级预警即蓝色预警
        if (dangerLevel == null) {
            dangerLevel = DangerLevel.BLUE.getCode();
        }
        return analysisEvalDataViewManage.companyWarnStatisticsByLevel(regionId, dangerLevel);
    }

    @GetMapping("/carWarnStatistics/{regionId}")
    @ApiOperation("车辆综合预警分析")
    public List<MapDataVO> carWarnStatistics(@PathVariable Long regionId) {
        regionId = CodeUtil.convertRegionCodeToId(regionId);
        return analysisEvalDataViewManage.carWarnStatistics(regionId);
    }

    @GetMapping("/carWarnStatisticsByLevel")
    @ApiOperation("车辆红色预警")
    public List<DataChartVo> carWarnStatisticsByLevel(@RequestParam("regionId") Long regionId,
                                                          @RequestParam(value = "dangerLevel", required = false) Integer dangerLevel) {
        regionId = CodeUtil.convertRegionCodeToId(regionId);
        // 默认查询红色预警
        if (dangerLevel == null) {
            dangerLevel = DangerLevel.RED.getCode();
        }
        return analysisEvalDataViewManage.carWarnStatisticsByLevel(regionId, dangerLevel);
    }

}
