package com.ningdatech.carapi.road.constant;

import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @return
 * @author CMM
 * @since 2022/12/20 14:10
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "VehicleDangerLevelEnum", description = "车辆风险等级-枚举")
public enum RoadBehaviorTypeEnum {
    /**
     * 道路异常行为类型
     */
    DRIVER(1, "驾驶员行为异常"),

    SPEED(2, "车辆速度异常"),

    VIDEO(3,"道路监控异常");



    private Integer code;
    private String desc;

    public String getDesc() {
        return desc;
    }

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

    public static String getDescByCode(Integer code) {
        if(Objects.isNull(code)){
            return StringUtils.EMPTY;
        }
        for (RoadBehaviorTypeEnum t : RoadBehaviorTypeEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.desc;
            }
        }
        return StringUtils.EMPTY;
    }

    public static Integer getCodeByDesc(String desc) {
        if(StringUtils.isBlank(desc)){
            return null;
        }
        for (RoadBehaviorTypeEnum t : RoadBehaviorTypeEnum.values()) {
            if (desc.equals(t.getDesc())) {
                return t.code;
            }
        }
        return null;
    }

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