package com.ningdatech.carapi.safe.controller;

import com.alibaba.fastjson.JSONObject;
import com.ningdatech.carapi.car.datascreen.model.dto.DataScreenParam;
import com.ningdatech.carapi.common.util.CodeUtil;
import com.ningdatech.carapi.safe.model.dto.LongitudeLatitudeDTO;
import com.ningdatech.carapi.safe.service.SecurityManageDataScreenService;
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/safe/data-screen")
@Api(value = "Security", tags = "安全管理-大屏")
@RequiredArgsConstructor
public class SecurityManageDataScreenController {

    private final SecurityManageDataScreenService securityManageDataScreenService;
    private static final Integer OUT_DANGER = 1;
    private static final Integer INJURIES = 2;
    private static final Integer DEATH_TOLL = 3;

    @ApiOperation(value = "近三年出险次数对比", notes = "近三年出险次数对比")
    @GetMapping("/out-danger")
    public JSONObject outDanger(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return securityManageDataScreenService.getInsureAnalysis(param,OUT_DANGER);
    }

    @ApiOperation(value = "近三年受伤人数对比", notes = "近三年受伤人数对比")
    @GetMapping("/injuries")
    public JSONObject injuries(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return securityManageDataScreenService.getInsureAnalysis(param,INJURIES);
    }

    @ApiOperation(value = "近三年死亡人数对比", notes = "近三年死亡人数对比")
    @GetMapping("/death")
    public JSONObject death(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return securityManageDataScreenService.getInsureAnalysis(param,DEATH_TOLL);
    }

    @ApiOperation(value = "浙江省事故分布", notes = "浙江省事故分布")
    @GetMapping("/accident-distribute")
    public List<LongitudeLatitudeDTO> accidentDistribute(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return securityManageDataScreenService.getAccidentLongitudeLatitude(param);
    }

    @ApiOperation(value = "本月累积出险时段统计", notes = "本月累积出险时段统计")
    @GetMapping("/out-danger-current-month")
    public JSONObject outDangerCurrentMonth(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return securityManageDataScreenService.getOutDangerCurrentMonth(param);
    }

    @ApiOperation(value = "近30天超速车辆数", notes = "近30天超速车辆数")
    @GetMapping("/overspeed")
    public JSONObject overspeed(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return securityManageDataScreenService.getOverSpeedCurrentMonth(param);
    }

    @ApiOperation(value = "近三年各城市出险次数", notes = "近三年各城市出险次数")
    @GetMapping("/out-danger-city")
    public JSONObject outDangerCity(@Valid @ModelAttribute DataScreenParam param) {
        CodeUtil.convertRegionCodeToId(param);
        return securityManageDataScreenService.getOutDangerCity(param);
    }
}
