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

namespace skyscraper5.Dvb.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x5B,"NIT")]
    class MultilingualNetworkNameDescriptor : TsDescriptor
    {
        public MultilingualNetworkNameDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
            while (ms.GetAvailableBytes() > 4)
            {
                string k = Encoding.ASCII.GetString(ms.ReadBytes(3));
                byte networkNameLength = ms.ReadUInt8();
                string v = En300468AnnexATextDecoder.GetInstance().Decode(ms.ReadBytes(networkNameLength));
                result.Add(new KeyValuePair<string, string>(k, v));
            }

            MultilingualNetworkName = result.AsReadOnly();
        }

        public ReadOnlyCollection<KeyValuePair<string, string>> MultilingualNetworkName { get; private set; }
    }
}
