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.T2MI.Packets
{
    [SkyscraperPlugin]
    [T2MiPacketType(0x00)]
    internal class _0x00_BasebandFrame : T2MiPacket
    {
        public _0x00_BasebandFrame(T2MIHeader header, byte[] buffer) : base(header, buffer)
        {
            if (buffer.Length < 3)
            {
                Valid = false;
                return;
            }
            MemoryStream ms = new MemoryStream(buffer, false);
            FrameIndex = ms.ReadUInt8();
            PlpId = ms.ReadUInt8(); // t2packet[7]

            byte readUInt8 = ms.ReadUInt8(); //t2packet[8]
            InterleavingFrameStart = (readUInt8 & 0x80) != 0;
            RFU = (readUInt8 & 0x7f);

            BasebandFrame = ms.ReadBytes(ms.GetAvailableBytes());
            Valid = true;
        }

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

        public int RFU { get; private set; }

        public bool InterleavingFrameStart { get; private set; }

        public byte PlpId { get; private set; }

        public byte FrameIndex { get; private set; }
    }
}
