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

namespace skyscraper5.Dvb.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x55,"EIT")]
    [BannedTable("PMT")]
    class ParentalRatingDescriptor : TsDescriptor
    {
        public ParentalRatingDescriptor(byte[] buffer)
        {
            if (buffer.Length % 4 != 0)
                return;

            ParentalRatings = new Tuple<string, int>[buffer.Length / 4];
            for (int i = 0; i < buffer.Length; i += 4)
            {
                string countryCode = Encoding.ASCII.GetString(buffer, i, 3);
                byte age = buffer[i + 3];
                if (age >= 0x00 && age <= 0x0f)
                {
                    ParentalRatings[i / 4] = new Tuple<string, int>(countryCode, age + 3);
                }
            }

            base.Valid = true;
        }
        

        public Tuple<string, int>[] ParentalRatings;
    }
}
