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

namespace PSO2SERVER.Protocol.Handlers
{
    [PacketHandlerAttr(0x1A, 0x02)]
    public class DeleteMailRequest : PacketHandler
    {
        public struct DeleteMailRequestPacket
        {
            public List<MailId> ids;
        }

        public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
        {
            var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
            Logger.WriteHex(info, data);

            var reader = new PacketReader(data, position, size);
            var pkt = new DeleteMailRequestPacket();
            pkt.ids = new List<MailId>();

            var count = reader.ReadMagic(0xBC5F, 0x0B);
            for (int i = 0; i < count; i++)
            {
                var id = reader.ReadStruct<MailId>();
                pkt.ids.Add(id);
            }

            Logger.WriteObj(pkt);

            context.SendPacket(new DeletedMailPacket(pkt.ids));
        }
    }
}
