using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.Plugins;
using skyscraper5.Skyscraper.Scraper;
using skyscraper5.Skyscraper.Scraper.StreamAutodetection;
using skyscraper5.src.InteractionChannel;
using skyscraper5.src.InteractionChannel.Model;
using skyscraper5.src.InteractionChannel.Model.Descriptors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper5.src.Skyscraper.Scraper.StreamAutodetection.Contestants
{
	[SkyscraperPlugin]
	internal class InteractionChannelContestant : Contestant, InteractionChannelHandler, IDisposable
	{
		public InteractionChannelContestant(int pid)
			: base("Interaction channel for satellite distribution systems",pid)
		{
			InteractionChannelPsiGatherer interactionChannelPsiGatherer = new InteractionChannelPsiGatherer();
			interactionChannelPsiGatherer.Handler = this;
			PacketProcessor = new PsiDecoder(pid, interactionChannelPsiGatherer);
		}

		public override void DeclareWinner(SkyscraperContext skyscraperContext, int pid, ProgramContext programContext)
		{
			throw new NotImplementedException();
		}

		public override void Introduce(ProgramContext programContext)
		{
			
		}

		public override void Dispose()
		{

		}

		public int GetRmtTransmissionStandard(ushort networkId)
		{
			throw new NotImplementedException();
		}

		public void OnContentionControl(PhysicalAddress macAddress, _0xab_ContentionControlDescriptor descriptor)
		{
			Score++;
		}

		public void OnCorrectionControl(PhysicalAddress macAddress, _0xac_CorrectionControlDescriptor descriptor)
		{
			Score++;
		}

		public void OnCorrectionMessage(ushort interactiveNetworkId, Cmt cmt)
		{
			if (cmt.Entries.Length > 0)
			{
				Score++;
			}
		}

		public void OnCorrectionMessage(PhysicalAddress mac, _0xa1_CorrectionMessageDescriptor cmd)
		{
			Score++;
		}

		public void OnFrameComposition(ushort interactiveNetworkId, Fct fct)
		{
			if (fct.Frames.Length > 0)
			{
				Score++;
			}
		}

		public void OnInteractionChannelError(InteractionChannelErrorState unexpectedTable)
		{
			Score--;
		}

		public void OnNetworkLayerInfo(PhysicalAddress macAddress, _0xa0_NetworkLayerInfoDescriptor descriptor)
		{
			Score++;
		}

		public void OnRcsMap(Rmt rmt)
		{
			if (rmt.Linkages != null)
			{
				if (rmt.Linkages.Count > 0)
				{
					Score++;
					return;
				}
			}
			if (rmt.TransportStreams != null)
			{
				if (rmt.TransportStreams.Count > 0)
				{
					Score++;
				}
			}
		}

		public void OnSatellitePosition(ushort interactiveNetworkId, Spt spt)
		{
			if (spt.Satellites.Length > 0)
			{
				Score++;
			}
		}

		public void OnSuperframeComposition(ushort interactiveNetworkId, Sct sct)
		{
			if (sct.Superframes.Length > 0)
			{
				Score++;
			}
		}

		public void OnTerminalBurstTimePlan(ushort interactiveNetworkId, Tbtp tbtp)
		{
			if (tbtp.Frames.Length > 0)
			{
				Score++;
			}
		}

		public void OnTimeslotComposition(ushort interactiveNetworkId, Tct tct)
		{
			if (tct.Timeslots.Length > 0)
			{
				Score++;
			}
		}

		public void OnTransmissionModeSupport(ushort interactiveNetworkId, Tmst tmst)
		{
			if (tmst.Modes.Length > 0)
			{
				Score++;
			}
		}
	}
}
