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

namespace skyscraper8.Mhp.Descriptors
{
    [SkyscraperPlugin]
    [TsDescriptor(0x13, "AIT")]
    internal class _0x13_ProviderUsageDescriptor : TsDescriptor
    {
        public _0x13_ProviderUsageDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            while (ms.GetAvailableBytes() > 2)
            {
                byte providerNameLength = ms.ReadUInt8();
                if (providerNameLength > 0)
                {
                    if (ms.GetAvailableBytes() > providerNameLength)
                    {
                        if (providerNames == null)
                            providerNames = new List<string>();
                        providerNames.Add(ms.ReadUTF8FixedLength(providerNameLength));
                        Valid = true;
                    }
                }
            }
            if (providerNames == null)
                Valid = false;
            else if (providerNames.Count == 0)
                Valid = false;
        }

        private List<string> providerNames;
    }
}
