package com.cico.nest.lcdp.boot.core.qxsd.domain.event;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zws
 * @date 2024/8/15
 */
public enum EventType {

    hasten(0, "急加速"),
    deceleration(1, "急减速"),
    implement_lane_changes(2, "实线变道"),
    serpentine_driving(3,"蛇形驾驶"),
    retrograde(4,"逆行"),
    congestion(5,"拥堵"),
    suspicious_events(6,"可疑事件"),
    rear_end_chase(7,"事故"),
    parking(8,"违章停车"),

    slow_driving(9,"缓慢行驶"),
    super_slow_driving(10,"超慢行驶"),
    stop(11,"停驶"),
    pedestrian(12,"行人"),
    spill(13,"抛洒物"),
    fire(14,"火灾"),
    abnormal_weather(15,"异常天气"),

    overspeed(16,"超速"),

    intrude(17,"闯入"),
    not_flow_lane(18,"不按车道行驶"),
    non_motor(19,"非机动车"),
    danger_truck(20,"危化品车辆"),

    other(100,"其他"),
    nothing(99,"无"),
    motor_intrude(22,"机动车闯禁行"),
    bus(21,"大型客车"),
    ;

    public final int type;

    public final String desc;



    EventType(Integer type, String desc){
        this.desc = desc;
        this.type = type;
    }

    public static EventType findByType(Integer type) {
        for (EventType eventType : EventType.values()) {
            if (eventType.type == type) {
                return eventType;
            }
        }
        return other;
    }

    /**
     * 首页需要分组的
     * 交通事故：追尾、刮擦、翻车、撞固定物、撞行人、撞抛洒物、车辆起火（火灾）
     * 路面状况：抛洒物、违章停车、停驶、逆行、非机动车、行人、急加速、急减速、蛇形驾驶、机动车闯禁行、不按车道行驶、拥堵、缓慢行驶、危化品车、大型客车、违法变道、超速、可疑事件
     * 车辆故障：抛锚、爆胎、
     * 道路施工：日常养护(占道)、专项工程(占道)、临时抢修(占道)、日常养护(断路)、专项工程(断路)、临时抢修(断路)、专项工程(借道)）、临时抢修(借道)、拓宽施工
     * 其他：
     */
    public static Map<String,TypeStatistics> getTypeStatistics(){
        Map<String,TypeStatistics> map = new HashMap(5);
        map.put("交通事故",new EventType.TypeStatistics().setTypes(List.of(7,14)));
        map.put("路面状况",new TypeStatistics().setTypes(List.of(0,1,2,3,4,5,6,8,16,22,21,9,10,11,12,13,17,18,19,20)));
        map.put("车辆故障",new TypeStatistics());
        map.put("道路施工",new TypeStatistics());
        map.put("其他",new TypeStatistics().setTypes(List.of(100,99,15)));
        return map;
    }


    /**
     * 获取非机动车事件类型
     * @return
     */
    public static List<Integer> getTypeNonVehicle(){
        // 行人、火灾、异常天气、无事件、其他
        return Arrays.asList(12,14,15,99,100);
    }

    @Data
    @Accessors(chain = true)
    public static class TypeStatistics{
        private List<Integer> types = new ArrayList<>();
        private long count = 0;
    }

}
