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

namespace FiestaBot.Zone.Handlers
{
    internal class Zone04Handler
    {
        [ZonePacketHandler(4, 53)]
        public static void CharacterUpdateStats(ZoneClient Socket, Packet Packet)
        {
            //we don't care about this?
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 56)]
        public static void CharacterInfo(ZoneClient Socket, Packet Packet)
        {
            Packet.ReadInt(out int ID);
            Packet.ReadString(out string Name, 16);
            Packet.ReadByte(out byte Slot);
            Packet.ReadByte(out byte Level);
            Packet.ReadLong(out long Exp);
            Packet.ReadInt(out int Unk00);
            Packet.ReadShort(out short HPStones);
            Packet.ReadShort(out short SPStones);
            Packet.ReadUInt(out uint HP);
            Packet.ReadUInt(out uint SP);
            Packet.ReadInt(out int Fame);
            Packet.ReadLong(out long Money);
            Packet.ReadString(out string MapInx, 12);
            Packet.ReadInt(out int PosX);
            Packet.ReadInt(out int PosY);
            Packet.ReadByte(out byte Rotation);
            Packet.ReadByte(out byte STR);
            Packet.ReadByte(out byte END);
            Packet.ReadByte(out byte DEX);
            Packet.ReadByte(out byte INT);
            Packet.ReadByte(out byte SPR);
            Packet.ReadShort(out short Unk01);
            Packet.ReadUInt(out uint Killpoints);
            for (int x = 0; x < 7; x++) { Packet.ReadByte(out byte Unk02); }

            Socket.Manager.Character.ID = ID;
            Socket.Manager.Character.Name = Name;
            Socket.Manager.Character.Slot = Slot;

            Socket.Manager.Character.Level = Level;
            Socket.Manager.Character.Exp = Exp;

            Socket.Manager.Character.HPStones = HPStones;
            Socket.Manager.Character.SPStones = SPStones;

            Socket.Manager.Character.HP = HP;
            Socket.Manager.Character.SP = SP;

            Socket.Manager.Character.Fame = Fame;
            Socket.Manager.Character.Money = Money;

            Socket.Manager.Character.Position.MapInx = MapInx;
            Socket.Manager.Character.Position.X = PosX;
            Socket.Manager.Character.Position.Y = PosY;
            Socket.Manager.Character.Position.Z = Rotation;

            /*
            Socket.Manager.Character.Stats.STR = STR;
            Socket.Manager.Character.Stats.END = END;
            Socket.Manager.Character.Stats.DEX = DEX;
            Socket.Manager.Character.Stats.INT = INT;
            Socket.Manager.Character.Stats.SPR = SPR;
            */

            Socket.Manager.Character.Killpoints = Killpoints;

            Packet.Dispose();
        }

        [ZonePacketHandler(4, 57)]
        public static void CharacterLooks(ZoneClient Socket, Packet Packet)
        {
            Packet.ReadByte(out byte JobGender);
            Packet.ReadByte(out byte Hair);
            Packet.ReadByte(out byte HairColor);
            Packet.ReadByte(out byte Face);

            byte Gender = (byte)((JobGender >> 7) & 0x01);
            byte Class = (byte)((JobGender >> 2) & 0x1F);

            Socket.Manager.Character.Class = (Class)Class;
            Socket.Manager.Character.Style.Gender = (Gender)Gender;
            Socket.Manager.Character.Style.HairID = Hair;
            Socket.Manager.Character.Style.HairColorID = HairColor;
            Socket.Manager.Character.Style.FaceID = Face;

            Packet.Dispose();
        }

        [ZonePacketHandler(4, 58)]
        public static void CharacterQuestsBusy(ZoneClient Socket, Packet Packet)
        {
            //TODO: Quests in progress
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 59)]
        public static void CharacterQuestsCompleted(ZoneClient Socket, Packet Packet)
        {
            //TODO: Quests done
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 61)]
        public static void CharacterActiveSkills(ZoneClient Socket, Packet Packet)
        {
            //TODO: Active skills
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 62)]
        public static void CharacterPassiveSkills(ZoneClient Socket, Packet Packet)
        {
            //TODO: Passive skills
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 71)]
        public static void CharacterInventory(ZoneClient Socket, Packet Packet)
        {
            //0x08 equiped
            //0x09 inventory
            //TODO: Inventory
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 72)]
        public static void CharacterDataEnd(ZoneClient Socket, Packet Packet)
        {
            //TODO: Properly handle this
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 73)]
        public static void CharacterTitles(ZoneClient Socket, Packet Packet)
        {
            //TODO: Titles
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 74)]
        public static void CharacterTimedItems(ZoneClient Socket, Packet Packet)
        {
            //TODO: Timed items
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 91)]
        public static void CharacterUsablePoints(ZoneClient Socket, Packet Packet)
        {
            //TODO: Usable points
            Packet.Dispose();
        }

        [ZonePacketHandler(4, 198)]
        public static void AdminLevel(ZoneClient Socket, Packet Packet)
        {
            Packet.ReadByte(out byte AdminLevel);

            Socket.Manager.Character.AdminLevel = AdminLevel;

            Packet.Dispose();
        }

        [ZonePacketHandler(4, 212)]
        public static void ClientCommandsAccess(ZoneClient Socket, Packet Packet)
        {
            //useless as we're not using a client l0l
            Packet.Dispose();
        }
    }
}
