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 = "OffenseStatusTypeEnum", description = "车辆违章情况-枚举")
public enum OffenseStatusTypeEnum {
    /**
     * 车辆违章情况
     */
    Running_a_red_light(1, "闯红灯"),
    Crossing_the_line(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 (OffenseStatusTypeEnum t : OffenseStatusTypeEnum.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 (OffenseStatusTypeEnum t : OffenseStatusTypeEnum.values()) {
            if (desc.equals(t.getDesc())) {
                return t.code;
            }
        }
        return null;
    }

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