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 QualityStatusEnum {
    STATUS_10(10, "未质检"),
    STATUS_20(20, "部分质检"),
    STATUS_30(30, "已质检"),

    ;

    private final int key;

    private final String value;

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

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

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

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

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

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

        return inTypeEnum.getValue();
    }

}
