using DVBServices;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.Plugins;
using skyscraper5.Skyscraper.Scraper;
using skyscraper5.Skyscraper.Scraper.StreamAutodetection;
using skyscraper8.EPGCollectorPort.SkyscraperSide.MediaHighway2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper8.EPGCollectorPort.SkyscraperSide.OpenTV
{
	//Disabled due to the Huffmann Table being dynamically determined.
	//[SkyscraperPlugin]
	internal class OpenTvTitleContestant : Contestant, OpenTvHandler
	{
		public OpenTvTitleContestant(int pid) 
			: base("OpenTV Titles", pid)
		{
			PacketProcessor = new PsiDecoder(pid, new OpenTvTitleParser(this));
		}

		public override void Dispose()
		{

		}

		public override void DeclareWinner(SkyscraperContext skyscraperContext, int pid, ProgramContext programContext)
		{
			OpenTvScraper openTvScraper = skyscraperContext.PluginContext.FirstOrDefault(x => x is OpenTvScraper) as OpenTvScraper;
			if (openTvScraper == null)
			{
				openTvScraper = new OpenTvScraper(skyscraperContext);
				skyscraperContext.PluginContext.Add(openTvScraper);
			}

			skyscraperContext.DvbContext.RegisterPacketProcessor(pid, new PsiDecoder(pid, new OpenTvTitleParser(openTvScraper)));
		}

		public override void Introduce(ProgramContext programContext)
		{

		}

		public void OnNonOpenTvTraffic(int sourcePid, OpenTvExpectedDataType titles, int sectionTableId)
		{
			throw new NotImplementedException();
		}

		public void OnTitles(int sourcePid, int sectionTableId, OpenTVTitleSection titleSection)
		{
			Score++;
		}

		public void OnSummaries(int sourcePid, int sectionTableId, OpenTVSummarySection summarySection)
		{
			throw new NotImplementedException();
		}
	}
}
