package cn.van333.mt2ql.wxMessage.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 EventType implements IEnum {
    /**
     1 文本消息
     3 图片消息
     34 语音消息
     37 好友确认消息
     40 好友推荐消息
     42 共享名片
     43 视频消息
     44 主动撤回
     47 动画表情
     48 位置消息
     49 APP分享链接/文件
     50 VOIP消息
     51 微信初始化消息
     52 VOIP结束消息
     53 VOIP邀请
     62 小视频
     */
    TEXT(1, "文本消息"),
    IMAGE(3, "图片消息"),
    VOICE(34, "语音消息"),
    FRIEND_CONFIRM(37, "好友确认消息"),
    FRIEND_RECOMMEND(40, "好友推荐消息"),
    SHARE_CARD(42, "共享名片"),
    VIDEO(43, "视频消息"),
    REVOKE(44, "主动撤回"),
    ANIMATION(47, "动画表情"),
    LOCATION(48, "位置消息"),
    APP_SHARE_LINK(49, "APP分享链接/文件"),
    VOIP(50, "微信初始化消息"),
    VOIP_END(52, "VOIP结束消息"),
    VOIP_INVITE(53, "VOIP邀请"),
    SMALL_VIDEO(62, "小视频");
    private final int key;

    private final String name;

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

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

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

    public static Map<String, String> getKeyValue() {
        Map<String, String> map = new HashMap<>();
        EventType[] items = EventType.values();
        for (EventType 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>>();
        EventType[] items = EventType.values();
        for (EventType 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;
    }

}

