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

namespace skyscraper8.Docsis.DQoS
{
	public class AuthorizationBlock : Validatable
	{
		public AuthorizationBlock(byte[] buffer)
		{
			MemoryStream ms = new MemoryStream(buffer, false);
			while (ms.GetAvailableBytes() > 3)
			{
				byte type = ms.ReadUInt8();
				ushort length = ms.ReadUInt8();
				byte[] value = ms.ReadBytes(length);

				switch (type)
				{
					case 1:
						PacketCableAuthorizationBlock = new PacketCableAuthorizationBlockEncoding(value);
						break;
					default:
						//According to https://de.scribd.com/document/482615299/PKT-SP-DQOS-C01-071129 page 43,
						//Type 1 is the only valid value.
						Valid = false;
						return;
				}
			}
			Valid = true;
		}

		public PacketCableAuthorizationBlockEncoding PacketCableAuthorizationBlock { get; private set; }
	}
}
