package cn.van.business.enums;

/**
 * @author Leo
 * @version 1.0
 * @create 2023/12/19 0019 上午 10:27
 * @description：
 */

import com.fasterxml.jackson.annotation.JsonValue;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum FromType implements IEnum {
    /**
     * fromType	来源类型：1|私聊 2|群聊 3|公众号
     */
    PRIVATE(10009, "私聊"),
    GROUP(10008, "群聊"),
    MP(3, "公众号");
    private final int key;

    private final String name;

    FromType(int key, String name) {
        this.key = key;
        this.name = name;
    }

    public static FromType get(int key) {
        for (FromType e : FromType.values()) {
            if (e.getKey() == key) {
                return e;
            }
        }
        return null;
    }

    public static String getName(Integer key) {
        //if (Object.isNotEmpty(key)) {
        FromType[] items = FromType.values();
        for (FromType item : items) {
            if (item.getKey() == key) {
                return item.getName();
            }
        }
        //}
        return "";
    }

    public static Map<String, String> getKeyVlue() {
        Map<String, String> map = new HashMap<>();
        FromType[] items = FromType.values();
        for (FromType item : items) {
            map.put(item.getKey() + "", item.getName());
        }
        return map;
    }

    public static List<Map<String, Object>> getSelectItems() {
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        FromType[] items = FromType.values();
        for (FromType item : items) {
            Map<String, Object> map = new HashMap<>();
            map.put("label", item.getName());
            map.put("value", item.getKey());
            result.add(map);
        }
        return result;
    }

    @Override
    @JsonValue
    public Integer getKey() {
        return key;
    }

    @Override
    public String getName() {
        return name;
    }

}

