package com.ningdatech.carapi.analysis.common;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @return
 * @author CMM
 * @since 2022/12/20 14:10
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "VehicleDangerLevelEnum", description = "车辆风险等级-枚举")
public enum DangerLevelEnum {
    /**
     * 风险等级
     */
    LOW_RISK(1, "红色预警"),

    INTERMEDIATE_RISK(2, "橙色预警"),

    SECONDARY_RISK(3,"黄色预警"),

    SENIOR_RISK(4,"蓝色预警");



    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 (DangerLevelEnum t : DangerLevelEnum.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 (DangerLevelEnum t : DangerLevelEnum.values()) {
            if (desc.equals(t.getDesc())) {
                return t.code;
            }
        }
        return null;
    }

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