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

namespace PSO2SERVER.Protocol.Handlers
{
    [PacketHandlerAttr(0x0B, 0x20)]
    public class AcceptQuest : PacketHandler
    {
        public ObjectHeader quest_obj {  get; set; }
        public ushort diff {  get; set; }
        public ushort unk1 { get; set; }
        public uint[] unk2 { get; set; } = new uint[7];

        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);
            try
            {
                quest_obj = reader.ReadStruct<ObjectHeader>();
                diff = reader.ReadUInt16();
                unk1 = reader.ReadUInt16();
                for (int i = 0; i < 7; i++) { unk2[i] = reader.ReadUInt32(); }
            }
            catch (Exception ex)
            {
                Logger.WriteError("Error while processing AcceptQuest packet: " + ex.Message);
            }

            Logger.Write($"Quest Object: {quest_obj}, Difficulty: {diff}, unk1: {unk1}, unk2: {string.Join(", ", unk2)}");
        }
    }
}
