using PSO2SERVER.Models;
using PSO2SERVER.Protocol.Packets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace PSO2SERVER.Protocol.Handlers
{
    [PacketHandlerAttr(0x0B, 0x17)]
    public class QuestCategoryRequest : PacketHandler
    {
        public uint unk1 {  get; set; }
        public QuestType category { get; set; }

        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);
            unk1 = reader.ReadUInt32();
            category = (QuestType)reader.ReadUInt32();

            Logger.Write($"unk1 = {unk1} category = {category}");

            // What am I doing
            QuestDefiniton[] defs = new QuestDefiniton[1];
            for (int i = 0; i < defs.Length; i++)
            {
                defs[i].dateOrSomething = "2012/01/05";
                defs[i].quest_obj = new ObjectHeader(0x20, ObjectType.Quest);
                defs[i].questNameid = 30010;
                defs[i].playTime = QuestEstimatedTime.Short;
                defs[i].partyType = QuestPartyType.SinglePartyQuest;
                defs[i].difficulties = QuestDifficultyType.NORMAL | QuestDifficultyType.HARD | QuestDifficultyType.VERY_HARD | QuestDifficultyType.SUPER_HARD;
                defs[i].req_level = 1;
                // Not sure why but these need to be set for the quest to be enabled
                defs[i].quest_type = (QuestType)0xF1;
                defs[i].field_101 = 1;
            }

            context.SendPacket(new QuestCategoryPacket(defs));
            context.SendPacket(new QuestCategoryStopperPacket());
        }
    }

}
