package com.fjhx.enums.warehouse;

import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;

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

/**
 * 仓库类型枚举
 */
public enum WarehouseTypeEnum {
    WAREHOUSE_TYPE_1(1, "普通仓库"),
    WAREHOUSE_TYPE_2(2, "京东仓库"),
    WAREHOUSE_TYPE_3(3, "外场仓库"),
    WAREHOUSE_TYPE_99(99, "其他"),
    WAREHOUSE_TYPE_100(100, "处置仓"),
    ;

    private int key;

    private String value;

    private static Map<Integer, String> map = new LinkedHashMap<>();

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

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


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

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

    /**
     * 获取枚举map
     *
     * @return
     */
    public static Map<Integer, String> getMap() {
        if (Func.isNotEmpty(map)) {
            return map;
        }
        for (WarehouseTypeEnum ms : values()) {
            map.put(ms.key, ms.value);
        }
        return map;
    }

    /**
     * 通过key获取名称
     *
     * @param key
     * @return
     */
    public static String getNameByKey(Integer key) {
        if (key == null || key < 0) {
            return StringPool.EMPTY;
        }
        Map<Integer, String> map = getMap();
        return map.getOrDefault(key, StringPool.EMPTY);
    }

    public int getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

}
