package com.ssyf.task.websocket.msg;

import cn.hutool.json.JSONObject;
import com.ssyf.third.bmiss.model.LiveRoom;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class AuthMessageHandler implements WsMessageHandler {

    @Override
    public boolean supports(String scene, String type) {
        return "single".equals(scene) && ("success".equals(type) || "fail_token".equals(type));
    }

    @Override
    public void handle(Integer roomId, JSONObject message, LiveRoom liveRoom, String token) {
        String type = message.getStr("type");
        if ("fail_token".equals(type)) {
            log.error("[Room {}] Token Authentication Failed!", roomId);
            // 这里可以触发事件通知 Manager 进行重连或刷新 Token
        } else {
            log.info("[Room {}] Token Authentication Success.", roomId);
        }
    }
}