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(0x5C,"BAT")]
    [BannedTable("EIT")]
    public class MultilingualBouquetNameDescriptor : TsDescriptor
    {
        public MultilingualBouquetNameDescriptor(byte[] buffer)
        {
            if (buffer == null)
            {
                Valid = false;
                MultilingualBouquetName = new Dictionary<string, string>();
                return;
            }
            MemoryStream ms = new MemoryStream(buffer, false);
            Dictionary<string, string> result = new Dictionary<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[k] = v;
            }

            MultilingualBouquetName = result;
        }

        public Dictionary<string, string> MultilingualBouquetName { get; private set; }
    }
}
