using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Dvb.Descriptors;
using skyscraper5.Dvb.Psi;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.Skyscraper.Scraper.StreamAutodetection.Contestants
{
	[SkyscraperPlugin]
	class TimeContestant : Contestant, ITdtEventHandler, ITotEventHandler, IDisposable
    {
        public TimeContestant(int pid) : base("TDT/TOT", pid)
        {
            PacketProcessor = new PsiDecoder(pid, new TimetableParser(this, this));
        }

        public void OnTdtTime(DateTime utcTime)
        {
            Score++;
        }
        
        public void OnTotTime(DateTime utcTime, LocalTimeOffsetDescriptor ltod)
        {
            Score++;
        }

        public override void Dispose()
        {
            
        }

        public override void DeclareWinner(SkyscraperContext skyscraperContext, int pid, ProgramContext programContext)
        {
	        FreesatTunnelScraper fts = new FreesatTunnelScraper();
			skyscraperContext.DvbContext.RegisterPacketProcessor(pid, new PsiDecoder(pid, new Pid0x11Decoder(fts, fts)));
		}
    }
}
