import { NetManager } from '../../Framework/Net/NetManager';
import { MsgReqLogin } from '../../Shared/protocols/MsgReqLogin';
import { MsgReqMove } from '../../Shared/protocols/MsgReqMove';
import { MsgReqSend } from '../../Shared/protocols/MsgReqSend';
import { MsgResLogin } from '../../Shared/protocols/MsgResLogin';
import { MsgResMove } from '../../Shared/protocols/MsgResMove';
import { MsgResSend } from '../../Shared/protocols/MsgResSend';
import { LoginMessagePair } from './Pair/LoginMessagePair';
import { MoveMessagePair } from './Pair/MoveMessagePair';
import { SendMessagePair } from './Pair/SendMessagePair';

/**
 * 消息管理器 - 提供类型安全的消息发送方法
 */
export class MsgManager {
    private static _instance: MsgManager;

    static getInstance(): MsgManager {
        if (!this._instance) {
            this._instance = new MsgManager();
        }
        return this._instance;
    }

    private get netManager(): NetManager {
        return NetManager.getInstance();
    }

    /**
     * 发送登录请求
     * @param loginData 登录数据
     * @returns 登录响应
     */
    async login(loginData: MsgReqLogin): Promise<MsgResLogin | null> {
        return this.netManager.callMsg(new LoginMessagePair(), loginData);
    }

    /**
     * 发送移动请求
     * @param moveData 移动数据
     * @returns 移动响应
     */
    async move(moveData: MsgReqMove): Promise<MsgResMove | null> {
        return this.netManager.callMsg(new MoveMessagePair(), moveData);
    }

    /**
     * 发送消息请求
     * @param sendData 发送数据
     * @returns 发送响应
     */
    async send(sendData: MsgReqSend): Promise<MsgResSend | null> {
        return this.netManager.callMsg(new SendMessagePair(), sendData);
    }
}