package com.fjhx.entity.attachment.enums;

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

import java.util.LinkedHashMap;

/**
 * 文件类型枚举
 */
public enum AttachmentTypeEnum {
    TYPE_ONE(1, "面料问题反馈图片"),
    TYPE_TWO(2, "供应商其他资质"),
    ;

    private int key;

    private String value;

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

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

    /**
     * 获取枚举map
     *
     * @return
     */
    public static LinkedHashMap<Integer, String> getMap() {
        if (ObjectUtil.isNotEmpty(map)) {
            return map;
        }
        for (AttachmentTypeEnum 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;
        }
        LinkedHashMap<Integer, String> map = getMap();
        return map.getOrDefault(key, StringPool.EMPTY);
    }

    public int getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

}
