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

namespace skyscraper8.InteractionChannel
{
	/// <summary>
	/// Represents the structure in ETSI EN 301 545-2 V1.4.1, clause 6.4.3.1.1
	/// </summary>
	internal class GseTableStructure : Validatable
	{
		public GseTableStructure(byte[] buffer)
		{
			MemoryStream ms = new MemoryStream(buffer, false);
			TableId = ms.ReadUInt8();
			InteractiveNetworkId = ms.ReadUInt16BE();

			byte byteA = ms.ReadUInt8();
			VersionNumber = (byteA & 0x3e) >> 1;
			CurrentNextIndicator = (byteA & 0x01) != 0;

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

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

		public bool CurrentNextIndicator { get; private set; }

		public int VersionNumber { get; private set; }

		public ushort InteractiveNetworkId { get; private set; }

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