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 EventType implements IEnum {
    // New Events
    INJECTED_SUCCESS(10000, "注入成功"),
    ACCOUNT_CHANGED(10014, "账号变动事件"),
    GROUP_MESSAGE_RECEIVED(10008, "收到群聊消息"),
    PRIVATE_MESSAGE_RECEIVED(10009, "收到私聊消息"),
    OWN_MESSAGE_SENT(10010, "自己发出消息"),
    TRANSFER_EVENT(10006, "转账事件"),
    REVOKE_EVENT(10013, "撤回事件"),
    FRIEND_REQUEST(10011, "好友请求"),
    PAYMENT_EVENT(10007, "支付事件"),
    AUTH_EXPIRED(99999, "授权到期"),
    QR_CODE_PAYMENT_RECEIVED(10015, "二维码收款事件"),
    GROUP_MEMBER_CHANGED(10016, "群成员变动事件");
    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;
    }

}

