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

namespace PSO2SERVER.Protocol.Handlers
{
    [PacketHandlerAttr(0x1F, 0x02)]
    public class OrderListRequest : PacketHandler
    {
        public struct OrderListRequestPacket
        {
            public uint unk1;
            public string source;
            public uint unk3;
            public uint unk4;
            public uint unk5;
            public uint unk6;
        }

        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 packet = new OrderListRequestPacket
            {
                unk1 = reader.ReadUInt32(),
                source = reader.ReadAscii(0x70B2, 0x9E),
                unk3 = reader.ReadUInt32(),
                unk4 = reader.ReadUInt32(),
                unk5 = reader.ReadUInt32(),
                unk6 = reader.ReadUInt32(),
            };

            Logger.Write($"unk1 = {packet.unk1},source = {packet.source},unk3 = {packet.unk3},unk4 = {packet.unk4},unk5 = {packet.unk5},unk6 = {packet.unk6}");

            context.SendPacket(new OrderListPacket());
        }
    }
}
