using PSO2SERVER.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PSO2SERVER.Protocol.Packets
{
    public class MissionPassPacket : Packet
    {
        public uint Unk1 { get; set; }

        // Ongoing season ID.
        public uint CurSeasonId { get; set; }

        // Ongoing season name.
        public string CurSeason { get; set; }

        // Stars required to advance to the next tier.
        public uint StarsPerTier { get; set; }

        // Regular tier count.
        public uint Tiers { get; set; }

        // Overrun tier count.
        public uint OverrunTiers { get; set; }

        // Total tier count.
        public uint TotalTiers { get; set; }

        // Pass start timestamp.
        public uint StartDate { get; set; }

        // Pass end timestamp.
        public uint EndDate { get; set; }

        // Catchup period start timestamp.
        public uint CatchupStart { get; set; }

        public uint Unk11 { get; set; }

        // Banner ID for the ongoing season.
        public string CurBanner { get; set; }

        // SG price per tier.
        public uint PricePerTier { get; set; }

        // SG price for gold pass.
        public uint GoldPassPrice { get; set; }

        // Mission Pass rewards.
        public List<MissionPassItem> CurItems { get; set; }

        // Previous season ID.
        public uint LastSeasonId { get; set; }

        // Previous season name.
        public string LastSeason { get; set; }

        // Stars required to advance to the next tier (previous season).
        public uint LastStarsPerTier { get; set; }

        // Regular tier count (previous season).
        public uint LastTiers { get; set; }

        // Overrun tier count (previous season).
        public uint LastOverrunTiers { get; set; }

        // Total tier count (previous season).
        public uint LastTotalTiers { get; set; }

        // Pass start timestamp (previous season).
        public uint LastStartDate { get; set; }

        // Pass end timestamp (previous season).
        public uint LastEndDate { get; set; }

        // Catchup period start timestamp (previous season).
        public uint LastCatchupStart { get; set; }

        // Catchup period end timestamp (previous season).
        public uint LastCatchupEnd { get; set; }

        // Banner ID for the previous season.
        public string LastBanner { get; set; }

        // SG price per tier (previous season).
        public uint LastPricePerTier { get; set; }

        // SG price for gold pass (previous season).
        public uint LastGoldPassPrice { get; set; }

        // Mission Pass rewards (previous season).
        public List<MissionPassItem> LastItems { get; set; }

        public uint Unk30 { get; set; }

        public uint Unk31 { get; set; }

        // Default constructor
        public MissionPassPacket()
        {
            CurItems = new List<MissionPassItem>();
            LastItems = new List<MissionPassItem>();
        }


        #region implemented abstract members of Packet

        public override byte[] Build()
        {
            var pkt = new PacketWriter();
            pkt.Write(Unk1);
            pkt.Write(CurSeasonId);
            pkt.WriteUtf16(CurSeason, 0xB0C, 0x35);
            // Stars required to advance to the next tier.
            pkt.Write(StarsPerTier);
            // Regular tier count.
            pkt.Write(Tiers);
            // Overrun tier count.
            pkt.Write(OverrunTiers);
            // Total tier count.
            pkt.Write(TotalTiers);
            // Pass start timestamp.
            pkt.Write(StartDate);
            // Pass end timestamp.
            pkt.Write(EndDate);
            // Catchup period start timestamp.
            pkt.Write(CatchupStart);
            pkt.Write(Unk11);
            // Banner ID for the ongoing season.
            pkt.WriteUtf16(CurBanner, 0xB0C, 0x35);
            // SG price per tier.
            pkt.Write(PricePerTier);
            // SG price for gold pass.
            pkt.Write(GoldPassPrice);

            // Write CurItems count and each item
            pkt.WriteMagic(CurItems.Count, 0xB0C, 0x35);
            foreach (var item in CurItems)
            {
                pkt.WriteStruct(item);
            }

            // Write other properties
            pkt.Write(LastSeasonId);
            pkt.WriteUtf16(LastSeason, 0xB0C, 0x35);
            pkt.Write(LastStarsPerTier);
            pkt.Write(LastTiers);
            pkt.Write(LastOverrunTiers);
            pkt.Write(LastTotalTiers);
            pkt.Write(LastStartDate);
            pkt.Write(LastEndDate);
            pkt.Write(LastCatchupStart);
            pkt.Write(LastCatchupEnd);
            pkt.WriteUtf16(LastBanner, 0xB0C, 0x35);
            pkt.Write(LastPricePerTier);
            pkt.Write(LastGoldPassPrice);

            // Write LastItems count and each item
            pkt.WriteMagic(LastItems.Count, 0xB0C, 0x35);
            foreach (var item in LastItems)
            {
                pkt.WriteStruct(item);
            }

            // Write Unk30 and Unk31
            pkt.Write(Unk30);
            pkt.Write(Unk31);
            return pkt.ToArray();
        }

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

        #endregion
    }
}