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.Plugins;

namespace skyscraper5.Dvb.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x49,"BAT","SDT","Astra SGT")]
    [BannedTable("PMT","TSDT")]
    public class CountryAvailabilityDescriptor : TsDescriptor
    {
        public CountryAvailabilityDescriptor(byte[] buffer)
        {
            if (buffer.Length == 0)
            {
                CountryCodes = new string[0];
                return;
            }

            CountryAvailabilityFlag = (buffer[0] & 0x80) != 0;

            int numCountries = (buffer.Length - 1) / 3;
            CountryCodes = new string[numCountries];
            for (int i = 0; i < numCountries; i++)
            {
                CountryCodes[i] = Encoding.ASCII.GetString(buffer, 1 + (i * 3), 3);
            }

        }

        public string[] CountryCodes { get; private set; }

        public bool CountryAvailabilityFlag { get; private set; }
        
    }
}
