package com.ssyf.ws.constants;

/**
 * 命令类型枚举
 * 定义系统支持的所有命令类型
 */
public enum CommandType {
    
    // 认证相关命令
    AUTH_REQUEST("auth.request", "认证请求" ,false),
    AUTH_RESPONSE("auth.response", "认证响应" ,false),
    
    // 心跳命令
    HEARTBEAT("heartbeat", "心跳检测" ,false),
    
    // 聊天相关命令
    CHAT_INIT("chat.init", "聊天初始"),
    CHAT_SEND("chat.send", "发送消息"),
    CHAT_RECEIVE("chat.receive", "接收消息"),
    CHAT_STATUS_QUERY("chat.status.query", "查询消息状态"),
    CHAT_STATUS_UPDATE("chat.status.update", "更新消息状态"),
    CHAT_READ_CONFIRM("chat.read.confirm", "消息已读确认"),
    
    // 系统命令
    SYSTEM_NOTICE("system.notice", "系统通知"),
    ERROR_RESPONSE("error.response", "错误响应" ,false);
    
    private final String code;
    private final String description;
    //命令是否需要验证
    private Boolean auth = true;
    
    CommandType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    CommandType(String code, String description ,Boolean auth) {
        this.code = code;
        this.description = description;
        this.auth = auth;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }

    public boolean isAuth() {
        return auth || false;
    }
    
    /**
     * 根据code获取枚举
     */
    public static CommandType getByCode(String code) {
        for (CommandType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }
}