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 OpenTvTitleParser : IPsiProcessor
	{
		private readonly OpenTvHandler _handler;

		public OpenTvTitleParser(OpenTvHandler handler)
		{
			_handler = handler;
		}

		public void GatherPsi(PsiSection section, int sourcePid)
		{
			if (section.TableId >= 0xa0 && section.TableId <= 0xa7)
			{
				OpenTVTitleSection titleSection = OpenTVTitleSection.ProcessOpenTVTitleTable(section.GetData(),sourcePid,section.TableId);
				if (titleSection != null)
				{
					_handler.OnTitles(sourcePid, section.TableId, titleSection);
				}
			}
			else
			{
				if (section.TableId >= 0xa8 && section.TableId <= 0xab)
				{
					//Summaries.
					return;
				}

				_handler.OnNonOpenTvTraffic(sourcePid,OpenTvExpectedDataType.Titles, section.TableId);
			}
		}
	}
}
