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 = "BicycleStatusTypeEnum", description = "自行车情况-枚举")
public enum BicycleStatusTypeEnum {
    /**
     * 自行车情况
     */
    Bicycle_Collisions(1, "自行车碰撞"),
    Motorway_Intrusion(2, "自行车误入高速公路");

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

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