using System;
using System.Runtime.InteropServices;
using PSO2SERVER.Json;
using PSO2SERVER.Models;

namespace PSO2SERVER.Protocol.Packets
{
    class PartySetQuestPacket : Packet
    {
        public uint Name {  get; set; }
        public uint Difficulty { get; set; }
        public QuestType QuestType { get; set; }
        public QuestDef QuestDefiniton { get; set; }
        public QuestDiff QuestDifficulty { get; set; }
        public ObjectHeader Player { get; set; }
        public ushort unk1 { get; set; } = 0;
        public ushort unk2 { get; set; } = 0;

        public PartySetQuestPacket(uint name, uint difficulty, QuestData questDate, uint player_id)
        {
            Name = name;
            Difficulty = difficulty;
            QuestDefiniton = questDate.QuestDefiniton;
            QuestDifficulty = questDate.Difficulty;
            Player = new ObjectHeader(player_id, ObjectType.Player);
        }

        public override byte[] Build()
        {
            PacketWriter pkt = new PacketWriter();
            pkt.Write(Name); // Unknown
            pkt.Write(Difficulty); // Unknown
            pkt.Write((uint)QuestType);
            QuestDefiniton.WriteToStream(pkt);
            QuestDifficulty.WriteToStream(pkt);
            pkt.WriteObjectHeader(Player);
            pkt.Write(unk1);
            pkt.Write(unk2);
            return pkt.ToArray();
        }

        public override PacketHeader GetHeader()
        {
            return new PacketHeader(0x0E, 0x31, PacketFlags.None);
        }
    }
}
