using DVBServices;
using skyscraper5.Skyscraper.Scraper;
using skyscraper8.Skyscraper.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper8.EPGCollectorPort.SkyscraperSide.OpenTV
{
	internal class OpenTvScraper : OpenTvHandler
	{
		private readonly SkyscraperContext _skyscraperContext;
		private readonly IOpenTvDataStorage storage;
		private static PluginLogger _logger;

		public OpenTvScraper(SkyscraperContext skyscraperContext)
		{
			_skyscraperContext = skyscraperContext;
			storage = new OpenTvDataStorageImpl(skyscraperContext.DataStorage.GetPluginConnector());
			if (_logger == null)
			{
				_logger = PluginLogManager.GetLogger(GetType());
			}
		}

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

		public void OnTitles(int sourcePid, int sectionTableId, OpenTVTitleSection titleSection)
		{
			if (!_skyscraperContext.CurrentNetworkId.HasValue)
				return;
			if (!_skyscraperContext.CurrentTransportStreamId.HasValue)
				return;

			foreach (OpenTVTitleData titleData in titleSection.TitleHeader.TitleData)
			{
				if (!storage.TestForTitles(_skyscraperContext.CurrentNetworkId.Value, _skyscraperContext.CurrentTransportStreamId.Value, titleData.EventID, titleData.StartTime))
				{

				}
			}
		}

		public void OnSummaries(int sourcePid, int sectionTableId, OpenTVSummarySection summarySection)
		{
			if (!_skyscraperContext.CurrentNetworkId.HasValue)
				return;
			if (!_skyscraperContext.CurrentTransportStreamId.HasValue)
				return;

			throw new NotImplementedException();
		}
	}
}
