package com.m2pool.chat.constant;

import lombok.Getter;

/**
 * @Enums ExceptionEnum
 * @Description 自定义websocket 异常码枚举类
 * @Author yyb
 * @Date 2025/4/17 10:18
 */
@Getter
public enum ExceptionEnum {
    IP_LIMIT_CONNECT(1020, "本机连接数已达上限9,请先关闭已有链接,再重新链接"),
    MAX_LIMIT_CONNECT(1021, "服务器websocket连接数已达上限,服务器拒绝链接"),
    SET_PRINCIPAL_FAIL(1022, "websocket链接异常,用户身份设置失败"),
    GET_PRINCIPAL_FAIL(1023, "websocket链接异常,用户信息邮箱获取失败"),
    ACCOUNT_HAS_CONNECTED(1024, "当前登录用户在其他地方链接"),

    ROOM_NOT_EXIST(1025, "聊天室不存在，发送消息失败");


    private final int code;
    private final String description;

    ExceptionEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据枚举类,拼接一个返回给前端的状态信息
     * @param exceptionEnum 枚举类
     * @return 返回一个状态信息，供前端解析
     */
    public static String fromCode(ExceptionEnum exceptionEnum) {
        int code = exceptionEnum.getCode();
        String description = exceptionEnum.getDescription();
        return code+","+description;
    }

}
