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

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()
        {
            
        }

        private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
        public override void DeclareWinner(SkyscraperContext skyscraperContext, int pid, ProgramContext programContext)
        {
	        logger.ErrorFormat("{0} {1} not yet implemented", nameof(TimeContestant), nameof(DeclareWinner));
	        skyscraperContext.DvbContext.RegisterPacketProcessor(pid, new PacketDiscarder());
        }

        public override void Introduce(ProgramContext programContext)
        {
	        
        }
    }
}
