using System;
using FilterAPI.Networking;

using FilterManager.ManagerNetworking;

namespace FilterManager
{
    internal class GlobalPacket
    {
        public static void SendWhisperMessageClient(ManagerClient ClientSocket, String CharacterName, String Message, params Object[] Args)
        {
            String FormattedMessage = String.Format(Message, Args);

            using (var ClientPacket = new Packet(8, 12))
            {
                ClientPacket.WriteString(CharacterName, 16);
                ClientPacket.PacketWriter.Write(FormattedMessage);

                ClientSocket.SendPacketServer(ClientPacket);
            }
        }

        public static void SendWhisperMessageFromServer(ManagerClient ClientSocket, String CharacterName, String Message, params Object[] Args)
        {
            String FormattedMessage = String.Format(Message, Args);

            using (var ServerPacket = new Packet(8, 13))
            {
                ServerPacket.WriteString(CharacterName, 16);
                ServerPacket.PacketWriter.Write((Byte)0);
                ServerPacket.PacketWriter.Write(FormattedMessage);

                ClientSocket.SendPacketClient(ServerPacket);
            }
        }

        public static void SendWhisperMessageToServer(ManagerClient ClientSocket, String CharacterName, String Message, params Object[] Args)
        {
            String FormattedMessage = String.Format(Message, Args);

            using (var ServerPacket = new Packet(8, 15))
            {
                ServerPacket.WriteString(CharacterName, 16);
                ServerPacket.PacketWriter.Write(FormattedMessage);

                ClientSocket.SendPacketClient(ServerPacket);
            }
        }

        public static void SendWorldMessageClient(ManagerClient ClientSocket, String Message, params Object[] Args)
        {
            String FormattedMessage = String.Format(Message, Args);

            using (var ServerPacket = new Packet(8, 17))
            {
                ServerPacket.PacketWriter.Write(FormattedMessage);

                ClientSocket.SendPacketClient(ServerPacket);
            }
        }

        public static void SendCharacterNameTaken(ManagerClient ClientSocket)
        {
            using (var ServerPacket = new Packet(5, 4))
            {
                ServerPacket.PacketWriter.Write((Int16)385);

                ClientSocket.SendPacketClient(ServerPacket);
            }
        }

        public static void SendAllocation(ManagerClient ClientSocket, Boolean Sequencial = false)
        {
            using (var ServerPacket = new Packet(4, 75))
            {
                ServerPacket.PacketWriter.Write(Sequencial);

                ClientSocket.SendPacketClient(ServerPacket);
            }
        }
    }
}
