package com.ningdatech.carapi.company.enumeration;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * <p>
 * CompanyType
 * </p>
 *
 * @author WendyYang
 * @since 16:43 2022/11/3
 */
@Getter
public enum CompanyTypeEnum {
    /**
     * 管理单位
     */
    MANAGE_BU(0, "管理企业"),
    PRODUCT_BU(1, "生产企业"),
    LOGISTICS_BU(2,"物流企业"),
    OTHER(3,"其他");

    private final Integer code;
    private final String desc;

    CompanyTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String getDescByCode(Integer code) {
        if(Objects.isNull(code)){
            return StringUtils.EMPTY;
        }
        for (CompanyTypeEnum t : CompanyTypeEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.desc;
            }
        }
        return StringUtils.EMPTY;
    }

    public static Integer getCodeByDesc(String desc) {
        if(Objects.isNull(desc)){
            return null;
        }
        for (CompanyTypeEnum t : CompanyTypeEnum.values()) {
            if (desc.equals(t.getDesc())) {
                return t.code;
            }
        }
        return null;
    }

}
