using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.Dvb.Descriptors.Extension
{
	[SkyscraperPlugin]
	[ExtensionDescriptor(0x13,"NIT","BAT","SDT","EIT","PMT","SIT")]
    class UriLinkageDescriptor : Dvb.ExtensionDescriptor
    {
        public UriLinkageDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, true);
            UriLinkageType = ms.ReadUInt8();
            byte uriLength = ms.ReadUInt8();
            Uri = Encoding.ASCII.GetString(ms.ReadBytes(uriLength));
            if (UriLinkageType == 0x00 || UriLinkageType == 0x01)
            {
                MinPollingInterval = ms.ReadUInt16BE();
            }
        }

        public ushort? MinPollingInterval { get; private set; }

        public byte UriLinkageType { get; private set; }
        public string Uri { get; }
    }
}
