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 DriverVehicleTypeEnum {
    /**
     * 散装水泥运输车
     */
    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 (DriverVehicleTypeEnum t : DriverVehicleTypeEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.desc;
            }
        }
        return OTHER.desc;
    }

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

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

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

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

}
