using System;
using System.Collections.Generic;
using PSO2SERVER.Models;

namespace PSO2SERVER.Protocol.Packets
{
    public class LoadEquipedPacket : Packet
    {
        /// Player whose equipment is loaded.
        public ObjectHeader Player { get; set; } = new ObjectHeader();
        /// Player's equiped items.
        public List<EquipedItem> Items { get; set; } = new List<EquipedItem>();
        // 0-back unit
        // 1-arm unit
        // 2-leg unit
        // 3-outfit
        // 9-weapon
        public uint Unk1 { get; set; } = 0;
        public byte[] Unk2 { get; set; } = new byte[0x28];

        #region implemented abstract members of Packet

        public LoadEquipedPacket(uint accountid, List<EquipedItem> items)
        {
            Player = new ObjectHeader(accountid, ObjectType.Player);
            Items = items;
        }

        public override byte[] Build()
        {
            var pkt = new PacketWriter();
            pkt.WriteStruct(Player);
            pkt.WriteMagic((uint)Items.Count, 0xCF76, 0xB5);
            foreach (var item in Items)
            {
                pkt.WriteStruct(item);
            }
            pkt.Write(Unk1);
            pkt.Write(Unk2);
            return pkt.ToArray();
        }

        public override PacketHeader GetHeader()
        {
            return new PacketHeader(0x0F, 0x0C, PacketFlags.PACKED);
        }

        #endregion
    }
}