package com.fjhx.enums.apply;

import lombok.Getter;
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;

/**
 * 申购状态枚举
 */
@Getter
public enum ApplyPurchaseStatusEnum {
    STATUS_10(10, "申购审批中"),
    STATUS_20(20, "申购审批已驳回"),
    STATUS_30(30, "申购审批已通过"),
    STATUS_40(40, "采购审批中"),
    STATUS_50(50, "采购审批已驳回"),
    STATUS_60(60, "采购审批已通过"),
    STATUS_70(70, "已完成"),
    ;

    private final int key;

    private final String value;

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

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

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


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

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

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

    /**
     * 通过key获取名称
     */
    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);
    }

}
