using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.DsmCc.Descriptors;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.DsmCc.Message
{
	[SkyscraperPlugin]
	[DsmCcMessage(0x1006)]
    class DownloadServerInitiate : DsmCcMessage
    {
        public DownloadServerInitiate(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            ServerId = ms.ReadBytes(20);

            CompatibilityDescriptor = new CompatibilityDescriptor(ms);

            if (ms.GetAvailableBytes() < 2)
                return;
            ushort privateDataLength = ms.ReadUInt16BE();
            if (privateDataLength > ms.GetAvailableBytes())
                return;
            PrivateData = ms.ReadBytes(privateDataLength);
        }

        public byte[] PrivateData { get; private set; }

        public CompatibilityDescriptor CompatibilityDescriptor { get; private set; }

        public byte[] ServerId { get; private set; }
    }
}
