package com.ningdatech.carapi.common.constant;

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

import java.util.Objects;

/**
 * 违章类型
 *
 * @author PoffyZhang
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "ViolationTypeEnum", description = "违章类型-枚举")
public enum ViolationTypeEnum {
    /**
     * 无证驾驶
     */
    MISS_CERT(1, "无证驾驶"),

    /**
     * 闯红灯
     */
    RED_LIGHT(2, "闯红灯"),

    /**
     * 超载
     */
    OVER_LOAD(3, "超载"),

    /**
     * 违规路段
     */
    SECTION(4, "违规路段"),

    /**
     * 违规时间段
     */
    PERIOD(5, "违规时间段");


    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 (ViolationTypeEnum t : ViolationTypeEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.desc;
            }
        }
        return StringUtils.EMPTY;
    }


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

}
