using System;
using System.Runtime.InteropServices;

using PSO2SERVER.Models;

namespace PSO2SERVER.Protocol.Packets
{
    class QuestDifficultyPacket : Packet
    {
        private QuestDifficulty[] questdiffs;

        public QuestDifficultyPacket(QuestDifficulty[] questdiffs)
        {
            // Setup dummy difficulty entries
            for (int i = 0; i < questdiffs.Length; i++)
            {
                QuestDifficultyEntry difficulty = new QuestDifficultyEntry
                {
                    ReqLevel = 1,
                    SubClassReqLevel = 0,
                    MonsterLevel = 1,
                    Unk1 = 1,
                    AbilityAdj = 0,
                    DmgLimit = 0,
                    TimeLimit = 0,
                    TimeLimit2 = 0,
                    SuppTarget = 0xFFFFFFFF,
                    Unk2 = 7,
                    Enemy1 = 0xFFFFFFFF,
                    Unk3 = 3,
                    Enemy2 = 0xFFFFFFFF,
                    Unk4 = 3
                };

                questdiffs[i].difficulty1 = difficulty;
                questdiffs[i].difficulty2 = difficulty;
                questdiffs[i].difficulty3 = difficulty;
                questdiffs[i].difficulty4 = difficulty;
                questdiffs[i].difficulty5 = difficulty;
                questdiffs[i].difficulty6 = difficulty;
                questdiffs[i].difficulty7 = difficulty;
                questdiffs[i].difficulty8 = difficulty;
            }

            this.questdiffs = questdiffs;
        }

        public override byte[] Build()
        {
            PacketWriter writer = new PacketWriter();
            
            writer.WriteMagic((uint)questdiffs.Length, 0x292C, 0x5B);
            foreach (QuestDifficulty d in questdiffs)
            {
                writer.WriteStruct(d);
            }
            return writer.ToArray();
        }

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