using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FiestaBot.Instances.Networking;
using FiestaBot.Manager.Networking;

namespace FiestaBot.Manager.ClientPacket
{
    internal class ManagerPacket
    {
        public static void SendTransferKey(ManagerClient Socket)
        {
            byte[] Unwanted = new byte[18];

            Packet p = new Packet(3, 15);
            p.WriteBytes(Unwanted);
            p.WriteString(Program.TransferKey, 64);

            Socket.SendPacket(p);
        }

        public static void SendCharacterCreate(ManagerClient Socket, byte Slot, string charName, byte charClass, byte charGender)
        {
            Packet p = new Packet(5, 1);
            p.WriteByte(Slot);
            p.WriteString(charName, 16);
            p.WriteByte(Convert.ToByte(0x01 | (charClass << 2) | charGender << 7));
            if (charGender == 1) { p.WriteByte(4); } //MaleHair
            else { p.WriteByte(0); } //FemaleHair 
            p.WriteByte(0); //HairColor
            p.WriteByte(0); //Face
            Socket.LastSlot = Slot;
            Socket.SendPacket(p);
        }

        public static void SendCharacterDelete(ManagerClient Socket, byte Slot)
        {
            Packet p = new Packet(5, 7);
            p.WriteByte(Slot);
            Socket.SendPacket(p);
        }

        public static void SendCharacterSelect(ManagerClient Socket, byte Slot)
        {
            Socket.Character = Socket.AllCharacters.Find(x => x.Slot == Slot);

            Packet p = new Packet(4, 1);
            p.WriteByte(Slot);
            Socket.SendPacket(p);
        }

        public static void SendRequestAllData(ManagerClient Socket)
        {
            Packet QuickBar = new Packet(28, 2);
            Packet QuickBarState = new Packet(28, 4);
            Packet Unk00 = new Packet(28, 6);
            Packet Unk01 = new Packet(28, 10);
            Packet ClientSettings = new Packet(28, 12);
            Packet Shortcuts = new Packet(28, 14);

            Socket.SendPacket(QuickBar);
            Socket.SendPacket(QuickBarState);
            Socket.SendPacket(Unk00);
            Socket.SendPacket(Unk01);
            Socket.SendPacket(ClientSettings);
            Socket.SendPacket(Shortcuts);
        }

        public static void SendPartyInvite(ManagerClient Socket, string ToInvite)
        {
            Packet p = new Packet(14, 2);
            p.WriteString(ToInvite, 16);

            Socket.SendPacket(p);
        }

        public static void SendPartyReject(ManagerClient Socket, string InvitedBy)
        {
            Packet p = new Packet(14, 5);
            p.WriteString(InvitedBy, 16);
            Socket.SendPacket(p);
        }

        public static void SendFriendInvite(ManagerClient Socket, string ToAdd)
        {
            Packet p = new Packet(12, 5);
            p.WriteString(ToAdd, 16);

            Socket.SendPacket(p);
        }
    }
}
