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;

/**
 * 入库类型枚举
 */
@Getter
public enum OutTypeEnum {
    PURCHASE(1, "采购出库"),
    MANUAL(2, "手动出库"),
    ;

    private final int key;

    private final String value;

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

    private static final Map<Integer, OutTypeEnum> classMap = new HashMap<>();

    static {
        for (OutTypeEnum value : OutTypeEnum.values()) {
            classMap.put(value.getKey(), value);
        }
    }

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

    /**
     * 通过key获取名称
     */
    public static String getValueByKey(Integer key) {
        OutTypeEnum outTypeEnum = classMap.get(key);

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

        return outTypeEnum.getValue();
    }

}
