using Newtonsoft.Json;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;
using skyscraper5.src.Mpeg2.PacketFilter;
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(0xac,"TIM")]
	public class _0xac_CorrectionControlDescriptor : TsDescriptor
	{
		[JsonConstructor]
		public _0xac_CorrectionControlDescriptor(uint AcqResponseTimeout, uint SyncResponseTimeout, byte AcqMaxLosses, byte SyncMaxLosses)
		{
			this.AcqResponseTimeout = AcqResponseTimeout;
			this.SyncResponseTimeout = SyncResponseTimeout;
			this.AcqMaxLosses = AcqMaxLosses;
			this.SyncMaxLosses = SyncMaxLosses;
			Valid = true;
		}

		public _0xac_CorrectionControlDescriptor(byte[] buffer) 
		{ 
			MemoryStream ms  =new MemoryStream(buffer);
			AcqResponseTimeout = ms.ReadUInt32BE();
			SyncResponseTimeout = ms.ReadUInt32BE();
			AcqMaxLosses = ms.ReadUInt8();
			SyncMaxLosses = ms.ReadUInt8();
			Valid = true;
		}

		public uint AcqResponseTimeout { get; }
		public uint SyncResponseTimeout { get; }
		public byte AcqMaxLosses { get; }
		public byte SyncMaxLosses { get; }


		public override bool Equals(object obj)
		{
			return obj is _0xac_CorrectionControlDescriptor descriptor &&
				   AcqResponseTimeout == descriptor.AcqResponseTimeout &&
				   SyncResponseTimeout == descriptor.SyncResponseTimeout &&
				   AcqMaxLosses == descriptor.AcqMaxLosses &&
				   SyncMaxLosses == descriptor.SyncMaxLosses;
		}

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

		public override string ToString()
		{
			return "Correction Control";
		}
	}
}
