using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DVBServices;
using skyscraper5.Mpeg2;

namespace skyscraper8.EPGCollectorPort.SkyscraperSide.OpenTV
{
	internal class OpenTvSummaryParser : IPsiProcessor
	{
		private readonly OpenTvHandler _openTvScraper;

		public OpenTvSummaryParser(OpenTvHandler openTvScraper)
		{
			_openTvScraper = openTvScraper;
		}

		public void GatherPsi(PsiSection section, int sourcePid)
		{
			if (section.TableId >= 0xa8 && section.TableId <= 0xab)
			{
				OpenTVSummarySection summarySection = OpenTVSummarySection.ProcessOpenTVSummaryTable(section.GetData());
				if (summarySection != null)
				{
					_openTvScraper.OnSummaries(sourcePid, section.TableId, summarySection);
				}
			}
			else
			{
				if (section.TableId >= 0xa0 && section.TableId <= 0xa7)
				{
					//Titles
					return;
				}

				_openTvScraper.OnNonOpenTvTraffic(sourcePid, OpenTvExpectedDataType.Summaries, section.TableId);
			}
		}
	}
}
