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

namespace skyscraper5.src.InteractionChannel.Model.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0xab, "TIM")]
	public class _0xab_ContentionControlDescriptor : TsDescriptor
	{
		public _0xab_ContentionControlDescriptor()
		{

		}
		public _0xab_ContentionControlDescriptor(byte[] buffer)
		{
			MemoryStream ms = new MemoryStream(buffer, false);
			SuperframeId = ms.ReadUInt8();
			CscResponseTimeout = ms.ReadUInt32BE();
			CscMaxLosses = ms.ReadUInt8();
			MaxTimeBeforeRetry = ms.ReadUInt32BE();
			Valid = true;
		}

		public byte SuperframeId { get; set; }
		public uint CscResponseTimeout { get; set; }
		public byte CscMaxLosses { get; set; }
		public uint MaxTimeBeforeRetry { get; set; }

		public _0xab_ContentionControlDescriptor(byte superframeId, uint cscResponseTimeout, byte cscMaxLosses, uint maxTimeBeforeRetry)
		{
			SuperframeId = superframeId;
			CscResponseTimeout = cscResponseTimeout;
			CscMaxLosses = cscMaxLosses;
			MaxTimeBeforeRetry = maxTimeBeforeRetry;
		}

		public override bool Equals(object obj)
		{
			return obj is _0xab_ContentionControlDescriptor descriptor &&
				   SuperframeId == descriptor.SuperframeId &&
				   CscResponseTimeout == descriptor.CscResponseTimeout &&
				   CscMaxLosses == descriptor.CscMaxLosses &&
				   MaxTimeBeforeRetry == descriptor.MaxTimeBeforeRetry;
		}

		public override bool DescriptorEquals(TsDescriptor thatDescriptor)
		{
			return Equals(thatDescriptor);
		}

		public override string ToString()
		{
			return String.Format("Contention Control for Superframe {0}", SuperframeId);
		}
	}
}
