using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using moe.yo3explorer.skyscraper8.DVBI.Model;
using skyscraper5.Docsis;
using skyscraper5.Docsis.MacManagement;
using skyscraper5.Dvb.DataBroadcasting.IntModel;
using skyscraper5.Dvb.DataBroadcasting.SkyscraperVfs;
using skyscraper5.Dvb.Descriptors;
using skyscraper5.Dvb.Psi.Model;
using skyscraper5.Mhp.Si.Model;
using skyscraper5.Mpeg2.Descriptors;
using skyscraper5.Mpeg2.Psi.Model;
using skyscraper5.Scte35;
using skyscraper5.Skyscraper.IO.CrazycatStreamReader;
using skyscraper5.Skyscraper.Net;
using skyscraper5.src.InteractionChannel.Model;
using skyscraper5.src.InteractionChannel.Model2;
using skyscraper5.src.Skyscraper.FrequencyListGenerator;
using skyscraper5.T2MI.Packets;
using skyscraper5.Teletext.Wss;
using skyscraper8.DvbNip;
using skyscraper8.DvbNip.UiIntegration;
using skyscraper8.DvbSis;
using skyscraper8.GSE;
using skyscraper8.GSE.GSE;
using skyscraper8.Ietf.FLUTE;
using skyscraper8.InteractionChannel.Model;
using skyscraper8.InteractionChannel.Model2;
using skyscraper8.Ses;
using skyscraper8.Skyscraper.Drawing;
using skyscraper8.Skyscraper.FrequencyListGenerator;
using skyscraper8.Skyscraper.Scraper;
using skyscraper8.T2MI.Packets;

namespace skyscraper5.Skyscraper.Scraper
{
    public interface ISkyscraperUiJunction
    {
        void NotifyEvent(EitEvent eitEvent);
        void NotifySdtService(SdtService sdtService);
        void NotifyPatProgram(int pmtPid, ushort programId);
        void NotifyPmtProgram(ProgramMapping result, int pmtPid);
        void NotifyMpeTraffic(IpTrafficInfo iti, byte[] ipv4PacketLength);
        void NotifyAit(AitApplication aitApplication);
        void DsmCcModuleAdd(int elementaryPid, ushort moduleInfoModuleId, byte moduleInfoModuleVersion);
        void DsmCcModuleProgress(int elementaryPid, ushort moduleInfoModuleId, byte moduleInfoModuleVersion, double moduleInfoDownloadProgress);
        void DsmCcModuleComplete(int elementaryPid, ushort moduleModuleId, byte moduleModuleVersion);
        void NotifyWss(ushort programNumber, WssDataBlock wssDataBlock, int pid);
        void NotifyStreamTypeDetection(string contestantTag, int pid);
        void NotifyBat(BatBouquet batBouquet);
        void DsmCcVfs(VfsFile vfsFile);
        void NotifyTot(DateTime utcTime, LocalTimeOffsetDescriptor ltod);
        void NotifyTdt(DateTime utcTime);
        void NotifyCat(CaDescriptor caDescriptor);
        void NotifyScte35(ushort programNumber, SpliceInsert spliceInsert);
        void NotifyScte35(ushort programNumber, TimeSignal spliceInsert);
        void NotifyDocsisFrequency(uint? frequency, bool isUpstream, object mmm);
        void ShowFramegrab(int currentNetworkId, int transportStreamId, ushort mappingProgramNumber, int mappingStreamElementaryPid, byte[] imageData);

        IEnumerable<HumanReadableService> GetServices();
        void OnBlindscanOpenFoundFrquenciesWindow(List<BlindscanSearchResult> foundFrequencies, STD_TYPE tunerMetadataType);
        void OnBlindscanJobDone(bool success);
        void OnBlindscanErrorMessage(string blindscanningLowHorizontalAreaFailed);

        /// <summary>
        /// Called after the part of a band (e.g. Horizontal High) has completed blindscanning.
        /// Is supposed to move the puppets in the SDL2 based UI to their home position.
        /// </summary>
        void OnBlindscanBandComplete();

        /// <summary>
        /// Called before a BLScan operation begins.
        /// </summary>
        /// <param name="minimum">The minimum frequency to scan</param>
        /// <param name="currentProgress">The Frequency on which we're starting.</param>
        /// <param name="maximum">The maximum frequency to scan</param>
        void OnBlindscanBeforeBLScan(int minimum, int currentProgress, int maximum);

        /// <summary>
        /// Called before a BLScan operation ends.
        /// </summary>
        void OnBlindscanAfterBLScan();

        /// <summary>
        /// Called when a transponder is found during a BLScan2.
        /// </summary>
        /// <param name="searchResult"></param>
        /// <param name="polarityIndex"></param>
        /// <param name="lnbTypeMinimumFrequency"></param>
        /// <param name="lnbTypeMaximumFrequency"></param>
        void OnBlindscanSearchResult1Callback(BlindscanSearchResult searchResult, int polarityIndex, int lnbTypeMinimumFrequency, int lnbTypeMaximumFrequency);

        /// <summary>
        /// Called before a SetChannel operation is performed.
        /// </summary>
        /// <param name="blindscanResult"></param>
        void OnBlindscanBeforeSetChannel(BlindscanSearchResult blindscanResult);

        /// <summary>
        /// Called after a band (meaning e.g. Horizontal High) has been scraped.
        /// In the SDL2 version, this is supposed to move the puppets back to their home position.
        /// </summary>
        void OnScrapeBandComplete();

        /// <summary>
        /// Called after a single transponder has been scraped.
        /// In the SDL2 version, this is supposed to hide the pressure plate representing the transponder.
        /// </summary>
        /// <param name="blindscanResult"></param>
        void OnBlindscanScrapeTransponderComplete(BlindscanSearchResult blindscanResult);

        /// <summary>
        /// Called when beginning to gather the RF Spectrum.
        /// In the SDL2 version, this is supposed to create the ScottPlot window.
        /// </summary>
        void OnBlindscanBeginRfSpectrum();

        /// <summary>
        /// Called when a data point for the RF Spectrum is available.
        /// </summary>
        /// <param name="polarization"></param>
        /// <param name="frequency"></param>
        /// <param name="rf"></param>
        void OnBlindscanRfSpectrumEnqueueSample(SatelliteDeliverySystemDescriptor.PolarizationEnum polarization, int frequency, double rf);

        /// <summary>
        /// Called when the gathering of the RF Spectrum has been completed.
        /// In the SDL2 version, this is supposed to close the ScottPlotWindow.
        /// </summary>
        void OnBlindscanEndRfSpectrum();

        /// <summary>
        /// Called when beginning to gather an IQ Spectrum.
        /// In the SDL2 version, this is supposed to create a Surface for Pixel drawing.
        /// </summary>
        /// <param name="result"></param>
        void OnBlindscanBeginIqSpectrum(IqChartData result);

        /// <summary>
        /// Called when the gathering of an IQ Spectrum has been completed.
        /// In the SDL2 version, this is supposed to remove the Surface for Pixel drawing.
        /// </summary>
        void OnBlindscanEndIq();

        /// <summary>
        /// Called when a lock couldn't be acquired.
        /// In the SDL2 version, this is supposed to play the fail.wav sound.
        /// </summary>
        /// <param name="satelliteSr"></param>
        /// <param name="resultState"></param>
        void OnBlindscanLockFail(SearchResult satelliteSr, BlindscanResultState resultState);

		/// <summary>
		/// Called before SetFilter is called.
		/// In the SDL2 version, this is supposed to:
		/// 1) Spawn all these nice windows about PAT, CAT, PMT, EIT, etc...
		/// 2) Play the Success1.wav
		/// 3) Set the packet counters in foundFrequenciesWindow to 0.
		/// 4) Enable the Zap now button in the foundFrequenciesWindow.
		/// </summary>
		void OnBlindscanFilterSetUp();

		/// <summary>
		/// Called after we're done collecting packets from a transponder.
		/// In the SDL2 version, this is supposed to:
		/// 1) Disable the Zap now button in the foundFrequenciesWindow.
		/// </summary>
		void OnBlindscanScrapeStopCondition();

        /// <summary>
        /// Called after the packets collected from the transponder have all been processed.
        /// In the SDL2 version, this is supposed to:
        /// 1) Hide all the windows about DVB Tables
        /// </summary>
		void OnBlindscanAfterPacketDrain();

		/// <summary>
		/// Called when StreamReader has invoked a DvbCallback.
		/// </summary>
		/// <param name="errorCount">1 when the packet size is odd. 2 when out of memory</param>
		/// <param name="length">The size of the data StreamReader gave to the DvbCallback</param>
		void OnBlindscanPacketError(int errorCount, int length);

		void OnBlindscanPacketOk(int numPackets, int packetsQueueCount);

        /// <summary>
        /// Checks whether the user asks to abort scraping and switch to the next transponder.
        /// </summary>
        /// <returns>Returns true if the button has been pressed.</returns>
		bool IsZapNowRequested();

        /// <summary>
        /// Checks whether the user asks not to zap automatically.
        /// </summary>
        /// <returns>Returns true if the "Do not auto-zap" checkbox is checked in the FoundFrequenciesWIndow</returns>
        bool MayAutoZap();
		void NotifyNit(NitNetwork nitNetwork);
		void EnableUiFeature(SkyscraperUiFeature bbframeAnalysis);
		void OnIpMacNotification(int sourcePid, Platform platform, Target target, Operational operational);
		void OnSsuNotification(Dvb.SystemSoftwareUpdate.Model.UpdateNotificationGroup common, Dvb.SystemSoftwareUpdate.Model.UpdateNotificationTarget target, ushort programNumber);


        /// <summary>
        /// 
        /// </summary>
        /// <param name="bbHeader"></param>
        /// <param name="payload">The payload begins at byte 11</param>
		void OnBbframe(BBHeader bbHeader, byte[] payload);
		void OnDetectionOfInnerTs(SkyscraperContext child, object identifier);
		void NotifyGsePacket(ushort value, byte[] gseDataBytes, GseLabel label);
		void OnDvbNipFileArrival(FluteUiHandle fuh);
		void OnDvbNipMulticastGatewayConfiguration(NipActualCarrierInformation carrier, MulticastGatewayConfigurationType multicastGatewayConfiguration);
		void OnDvbNipCarrierDetected(NipActualCarrierInformation currentCarrierInformation);
		void OnDvbNipPrivateDataSignallingManifest(PrivateDataSignallingManifestType privateDataSignallingManifest);
		void OnDvbNipServiceListEntryPoints(NipActualCarrierInformation currentCarrierInformation, ServiceListEntryPoints serviceListEntryPoints, DateTime dvbNipTime);
		void OnDvbNipServiceList(NipActualCarrierInformation currentCarrierInformation, string serviceListId1, ServiceListType serviceListId2);
		void OnDvbNipTimeOffsetFile(NipActualCarrierInformation currentCarrierInformation, TimeOffsetFileType timeOffsetFile);
		void OnDvbNipNetworkInformationFile(NipActualCarrierInformation currentCarrierInformation, NetworkInformationFileType networkInformationFile);
		void DvbNipServiceInformation(NipActualCarrierInformation currentCarrierInformation, ServiceInformationFileType serviceInformationFile);
		void OnDvbNipFileAnnouncement(FDTInstanceType flute);
		void OnAstraSgtList(SgtList list);
		void OnAstraSgtService(SgtService child);
		void NotifyTransportStreamId(int tsid, int nid);
		void OnDvbSisCat(int sourcePid, SisCatContainer catContainer);
		void OnDvbSisEit(int sourcePid, SisEitContainer eitContainer);
		void OnDvbSisFti(int relatedPid, _0xF0_FramingTimingInformation fti);
		void OnDvbSisTimestamp(int pid, _0x20_DvbT2Timestamp t2Timestamp);
		void OnDvbSisPat(int sourcePid, SisPatContainer patContainer);
		void OnDvbSisSdt(int sourcePid, SisSdtContainer sdtContainer);
		void OnDvbSisDsaci(ushort currentDsaGroupId, int versionNumber, byte sectionNumber, byte lastSectionNumber, Stream dsaci);
		void OnDvbSisPmt(int sourcePid, SisPmtContainer pmtContainer);
		void OnDvbSisNit(int sourcePid, SisNitContainer nitContainer);
		void OnDvbSisTdt(int sourcePid, DateTime? utcTime);
		void OnRcs2Rmt(Rmt rmt);
		void OnRcs2Tmst(ushort networkId, Tmst tmst);
		void OnRcs2Tmst2(ushort interactiveNetworkId, Tmst2 tmst2);
		void OnRcs2Tdt(ushort interactiveNetworkId, Rcs2Tdt tdt);
		void OnRcs2Nit(ushort interactiveNetworkId, RcsNit nit);
		void OnRcs2Bct(ushort networkId, Bct bct);
		void OnRcs2Fct2(ushort networkId, Fct2 fct2);
		void OnRcs2Tbtp2(ushort interactiveNetworkId, Tbtp2 tbtp2);
		void OnRcs2Tct(ushort interactiveNetworkId, Tct tct);
		void OnRcs2Tbtp(ushort interactiveNetworkId, Tbtp tbtp);
		void OnRcs2Sct(ushort interactiveNetworkId, Sct sct);
		void OnRcs2Spt(ushort interactiveNetworkId, Spt spt);
        void WneStoryDetect(uint embeddedSessionId);
        void WneStoryError(uint sessionId);
        void WneStoryProgress(uint sessionId, string filename, long fileCaught, uint fileSize);
        void WneStoryComplete(uint sessionId, string filename);
    }
}
