package com.ningdatech.carapi.common.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;

/**
 * 车辆类型
 *
 * @author PoffyZhang
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "VehicleTypeEnum", description = "车辆类型-枚举")
public enum VehicleTypeEnum {
    /**
     * 散装水泥运输车
     */
    BULK_CEMENT_TRUCK(1, "散装水泥运输车"),

    /**
     *预拌砂浆运输车
     */
    READY_MIXED_MORTAR_TRUC(2, "预拌砂浆运输车"),

    /**
     * 混凝土搅拌车
     */
    MIXER(3, "混凝土搅拌车"),

    /**
     * 移动泵车
     */
    KRHP(4, "移动泵车"),

    OTHER(99, "其他");


    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 OTHER.desc;
        }
        for (VehicleTypeEnum t : VehicleTypeEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.desc;
            }
        }
        return OTHER.desc;
    }

    public static String getDescByEnum(String e) {
        if(StringUtils.isBlank(e)){
            return null;
        }
        for (VehicleTypeEnum t : VehicleTypeEnum.values()) {
            String substring = e.substring(1, e.length() - 1);
            if (substring.equals(t.name())) {
                return t.desc;
            }
        }
        return null;
    }

    public static Integer getCodeByDesc(String desc) {
        if(StringUtils.isBlank(desc)){
            return OTHER.code;
        }
        for (VehicleTypeEnum t : VehicleTypeEnum.values()) {
            if (desc.equals(t.getDesc())) {
                return t.code;
            }
        }
        return OTHER.code;
    }

    public static VehicleTypeEnum getEnumByValue(Integer code) {
        if(Objects.isNull(code)){
            return null;
        }
        for (VehicleTypeEnum t : VehicleTypeEnum.values()) {
            if (code.equals(t.getCode())) {
                return t;
            }
        }
        return null;
    }

    public static VehicleTypeEnum getEnum(String desc) {
        if(Objects.isNull(desc)){
            return null;
        }
        for (VehicleTypeEnum t : VehicleTypeEnum.values()) {
            if (desc.equals(t.getDesc())) {
                return t;
            }
        }
        return null;
    }

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

}
