package com.ningdatech.carapi.radar.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 = "RadarCarTypeEnum", description = "雷达车辆类型-枚举")
public enum RadarCarTypeEnum {
    /**
     * 自行车情况
     */
    NON_MOTOR(1, "非机动车"),
    CAR(2, "小型车辆"),
    BUS(3, "中大型车辆"),
    UNKNOWN(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 (RadarCarTypeEnum t : RadarCarTypeEnum.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 (RadarCarTypeEnum t : RadarCarTypeEnum.values()) {
            if (desc.equals(t.getDesc())) {
                return t.code;
            }
        }
        return null;
    }

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