package com.ningdatech.carapi.car.datascreen.controller;

import com.ningdatech.carapi.car.datascreen.model.dto.DataScreenParam;
import com.ningdatech.carapi.car.datascreen.model.vo.*;
import com.ningdatech.carapi.car.datascreen.service.VehicleStatisticsService;
import com.ningdatech.carapi.common.util.CodeUtil;
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.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-10-22
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/vehicle/data-screen")
@Api(value = "vehicle", tags = "车辆管理-大屏")
@RequiredArgsConstructor
public class VehicleManageDataScreenController {

    private final VehicleStatisticsService vehicleStatisticsService;

    @ApiOperation(value = "车辆类型分布", notes = "车辆类型分布")
    @GetMapping("/vehicle-types")
    public List<VehicleTypeStatisticsVO> vehicleTypes(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return vehicleStatisticsService.getVehicleTypesStatistics(param);
    }

    @ApiOperation(value = "各区域车辆分布", notes = "各区域车辆分布")
    @GetMapping("/region")
    public List<RegionDistributionStatisticsVO> regionDistribution(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return vehicleStatisticsService.getRegionDistribution(param);
    }

    @ApiOperation(value = "保险机构出险分布", notes = "保险机构出险分布")
    @GetMapping("/insure")
    public List<InsureDistributionStatisticsVO> insureDistribution(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return vehicleStatisticsService.getInsureDistribution(param);
    }

    @ApiOperation(value = "运营商机构分布", notes = "运营商机构分布")
    @GetMapping("/operator")
    public List<OperatorDistributionStatisticsVO> operatorDistribution(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return vehicleStatisticsService.getOperatorDistribution(param);
    }

    @ApiOperation(value = "车辆使用年限分布", notes = "车辆使用年限分布")
    @GetMapping("/useful-life")
    public List<VehicleUsefulLifeStatisticsVO> usefulLiftDistribution(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return vehicleStatisticsService.getUsefulLiftDistribution(param);
    }

    @ApiOperation(value = "新增车辆数走势图", notes = "新增车辆数走势图")
    @GetMapping("/year")
    public List<YearVehicleStatisticsVO> newVehicleNum(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return vehicleStatisticsService.getNewVehicleNum(param);
    }
}
