package com.ningdatech.carapi.common.constant;

import com.ningdatech.carapi.sys.entity.enumeration.CodingRuleBehaviorTypeEnum;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static com.ningdatech.carapi.sys.entity.enumeration.CodingRuleBehaviorTypeEnum.*;

/**
 * 告警类型
 *
 * @author PoffyZhang
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "BgTypeEnum", description = "告警类型 新-枚举")
public enum BgTypeEnum {
    /**
     * 主动抓拍事件
     */
    ADAS_DSM_ALARM_100(100, "ADAS主动抓拍事件", adas_initiative_capture_events, false),
    ADAS_ALARM_101(101, "前向碰撞报警", forward_collision_warning, false),
    ADAS_ALARM_102(102, "车道偏离（左）报警", lane_departure_left_warning, false),
    ADAS_ALARM_103(103, "车道偏离（右）报警", lane_departure_right_warning, false),
    ADAS_ALARM_104(104, "频繁变道报警", change_lanes_frequently_warning, false),
    ADAS_ALARM_105(105, "车距过近(前车)报警", distance_too_close_warning, false),
    ADAS_ALARM_106(106, "行人碰撞报警", pedestrian_collisions_warning, false),
    ADAS_ALARM_107(107, "不礼让行人", no_comity_pedestrian, false),
    ADAS_ALARM_108(108, "道路标志识别事件", road_sign_recognition_event, false),
    ADAS_ALARM_109(109, "道路标识超速报警", road_signs_overspeed_warning, false),
    ADAS_ALARM_110(110, "路口快速通过报警", crossroads_quickly_through_warning, false),
    DSM_ALARM_200(200, "DSM主动抓拍事件", dsm_initiative_capture_events, false),
    DSM_ALARM_201(201, "探头遮挡报警", probe_cover_alarm, false),
    DSM_ALARM_202(202, "驾驶员人脸身份识别事件", driver_face_identification_events, false),
    DSM_ALARM_203(203, "换人驾驶报警", substitution_driving_alarm, false),
    DSM_ALARM_204(204, "超时驾驶报警", driver_timeout_alarm, false),
    DSM_ALARM_205(205, "疲劳驾驶报警", fatigue_driving_alarm, false),
    DSM_ALARM_206(206, "接打手持电话报警", holding_a_call_alarm, false),
    DSM_ALARM_207(207, "抽烟报警", smoke_alarm, false),
    DSM_ALARM_208(208, "分神驾驶报警", distracted_driving_alarm, false),
    DSM_ALARM_209(209, "驾驶员状态异常报警", driver_abnormal_state_alarm, false),
    DSM_ALARM_210(210, "未系安全带报警", not_wearing_seatbelt_alarm, false),
    DSM_ALARM_211(211, "驾驶员身份异常报警", driver_abnormal_status_alarm, false),
    BSD_ALARM_300(300, "后方接近报警", close_behind_alarm, false),
    BSD_ALARM_301(301, "左侧后方接近报警", left_rear_near_alarm, false),
    BSD_ALARM_302(302, "右侧后方接近报警", right_rear_near_alarm, false);

    private Integer code;
    private String desc;
    private CodingRuleBehaviorTypeEnum crbType;
    private Boolean hidden;


    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }


    public static List<Integer> listCode(Boolean hidden) {
        return Arrays.stream(values())
                .filter(w -> {
                    if (hidden == null) {
                        return Boolean.TRUE;
                    }
                    return hidden.equals(w.getHidden());
                })
                .map(BgTypeEnum::getCode)
                .collect(Collectors.toList());
    }


    public static String getDescByCode(int code) {
        for (BgTypeEnum t : BgTypeEnum.values()) {
            if (code == t.getCode()) {
                return t.desc;
            }
        }
        return StringUtils.EMPTY;
    }


    public static CodingRuleBehaviorTypeEnum getCrbTypeByCode(int code) {
        for (BgTypeEnum t : BgTypeEnum.values()) {
            if (code == t.getCode()) {
                return t.crbType;
            }
        }
        return null;
    }

    public boolean eq(String val) {
        return this.name().equals(val);
    }

}
