package cn.sikey.websocket.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: nelson
 * @Date: 2025/5/30
 * @Description: 消息类型
 */
@AllArgsConstructor
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum MessageType {
    /**
     * 心跳消息, 保持活跃的消息
     */
    HEARTBEAT_MESSAGES(1, ""),
    /**
     * ack 消息，服务器和客户端双方约定收到消息后的回执消息
     */
    ACK_MESSAGES(2, ""),
    /**
     * test文本消息
     */
    TEST_TEXT_MESSAGE(10, "publish.test.text"),

    ;

    @JsonValue
    private final Integer value;

    private final String routingKey;

    /**
     * 根据 value 获取 MessageType
     *
     * @param value value
     * @return MessageType
     */
    public static MessageType valueOf(Integer value) {
        for (MessageType messageType : MessageType.values()) {
            if (messageType.value.equals(value)) {
                return messageType;
            }
        }
        throw new RuntimeException("Invalid MessageType value: " + value);
    }
}
