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

namespace skyscraper5.DsmCc.Message
{
	[SkyscraperPlugin]
	[DsmCcMessage(0x1003)]
    class DownloadDataBlock : DsmCcMessage
    {
        public DownloadDataBlock(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);

            ModuleId = ms.ReadUInt16BE();
            ModuleVersion = ms.ReadUInt8();
            byte reserved = ms.ReadUInt8();
            BlockNumber = ms.ReadUInt16BE();

            BlockData = ms.ReadBytes(ms.GetAvailableBytes());
        }

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

        public ushort BlockNumber { get; private set; }

        public byte ModuleVersion { get; private set; }

        public ushort ModuleId { get; private set; }

        public uint DownloadId => base.Header.TransactionId;

        public void ForgetBlock()
        {
            BlockData = null;
        }
    }
}
