package com.ssyf.task.websocket.msg;

import cn.hutool.json.JSONObject;
import com.ssyf.task.websocket.WsStatisticsService;
import com.ssyf.third.bmiss.model.LiveRoom;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ClientIdMessageHandler implements WsMessageHandler {

    @Autowired
    private WsStatisticsService wsStatisticsService;

    @Override
    public boolean supports(String scene, String type) {
        // 根据文档：scene="single", type="client_id"
        return "single".equals(scene) && "client_id".equals(type);
    }

    @Override
    public void handle(Integer roomId, JSONObject message, LiveRoom liveRoom, String token) {
        String clientId = message.getStr("client_id");
        log.info("[Room {}] Received Client ID: {}", roomId, clientId);
        
        // 更新到 Redis 缓存
        wsStatisticsService.updateClientId(roomId, clientId);
    }
}