package com.group.robot.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.group.robot.RobotManagerInterface;
import com.group.robot.info.RobotInfo;
import com.group.robot.info.RoomInfo;
import taurus.client.TaurusClient;

/**
 * 扑克机器人处理器 - 负责协议转发
 */
public class PokerRobotHandler implements RobotManagerInterface {
    private static final Logger log = LoggerFactory.getLogger(PokerRobotHandler.class);
    
    private final RobotConnectionHandler connectionHandler;
    
    public PokerRobotHandler() {
        this.connectionHandler = RobotConnectionHandler.getInstance();
    }

    @Override
    public void connectRobot(RobotInfo robot) {
        try {
            log.info("扑克机器人 {} 正在连接到房间 {}", robot.getRobotId(), robot.getRoomId());
            
            //使用连接处理器进行连接
            connectionHandler.connectRobot(robot);
            
            // 设置机器人连接状态和房间信息
            robot.setConnected(true);

            log.info("扑克机器人 {} 开始连接到房间 {}, 玩法ID: {}", robot.getRobotId(), robot.getRoomId(), robot.getWanfaId());
        } catch (Exception e) {
            log.error("扑克机器人连接失败: " + robot.getRobotId(), e);
        }
    }
    
    @Override
    public void disconnectRobot(RobotInfo robot) {
        try {
            log.info("断开扑克机器人连接: {}", robot.getRobotId());
            
            //连接处理器断开连接
            connectionHandler.disconnectRobot(robot.getRobotId());
            
            robot.setConnected(false);
            log.info("扑克机器人 {} 连接已断开", robot.getRobotId());
        } catch (Exception e) {
            log.error("断开扑克机器人连接时发生错误: " + robot.getRobotId(), e);
        }
    }

}