package com.group.robot.handler;

import com.group.robot.RobotManagerInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.group.robot.info.RobotInfo;


/**
 * 麻将机器人处理器 - 处理麻将机器人连接
 */
public class MaJiangRobotHandler implements RobotManagerInterface {
    private static final Logger log = LoggerFactory.getLogger(MaJiangRobotHandler.class);

    private final RobotConnectionHandler robotConnectionHandler;

    public MaJiangRobotHandler() {
        this.robotConnectionHandler = RobotConnectionHandler.getInstance();
    }

    @Override
    public void connectRobot(RobotInfo robot) {
        try {
            //连接处理器进行连接
            robotConnectionHandler.connectRobot(robot);
        }catch (Exception e) {
            log.error("麻将机器人 {} 连接游戏服务器时发生异常", robot.getRobotId(), e);
            robot.setConnected(false);
        }
    }
    
    @Override
    public void disconnectRobot(RobotInfo robot) {
        try {
            log.info("断开麻将机器人连接: {}", robot.getRobotId());
            
            //连接处理器断开连接
            robotConnectionHandler.disconnectRobot(robot.getRobotId());
            
            robot.setConnected(false);

            log.info("麻将机器人 {} 连接已断开", robot.getRobotId());
        } catch (Exception e) {
            log.error("断开麻将机器人连接时发生错误: " + robot.getRobotId(), e);
        }
    }

}