package com.fjhx.enums.stock;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;
import org.springblade.core.tool.utils.StringPool;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 入库类型枚举
 */
@Getter
public enum InTypeEnum {
    PURCHASE(1, "采购入库"),
    MANUAL(2, "手动入库"),
    TRANSFER(7, "调仓入库"),
    ;

    private final int key;

    private final String value;

    InTypeEnum(int key, String value) {
        this.key = key;
        this.value = value;
    }

    private static final Map<Integer, InTypeEnum> CLASS_MAP = new HashMap<>();

    static {
        for (InTypeEnum value : InTypeEnum.values()) {
            CLASS_MAP.put(value.getKey(), value);
        }
    }

    /**
     * 根据key获取枚举
     */
    public static InTypeEnum getEnumByKey(Integer type) {
        return CLASS_MAP.get(type);
    }

    /**
     * 通过key获取名称
     */
    public static String getValueByKey(Integer key) {
        InTypeEnum inTypeEnum = CLASS_MAP.get(key);

        if (ObjectUtil.isEmpty(inTypeEnum)) {
            return StringPool.EMPTY;
        }

        return inTypeEnum.getValue();
    }

}
