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

namespace skyscraper5.Dvb.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x6f,"PMT")]
    [BannedTable("TSDT","NIT","EIT")]
    public class ApplicationSignallingDescriptor : TsDescriptor
    {
        public ApplicationSignallingDescriptor(byte[] buffer)
        {
            if (buffer.Length % 3 != 0)
            {
                Valid = false;
                return;
            }

            Applications = new ApplicationSignal[buffer.Length / 3];

            for (int i = 0; i < Applications.Length; i++)
            {
                Applications[i] = new ApplicationSignal();
                Applications[i].ApplicationType = BitConverter.ToUInt16(buffer, i * 3);
                Applications[i].ApplicationType &= 0x7fff;
                Applications[i].AitVersionNumber = buffer[(i * 3) + 2] & 0x1f;
            }
            Valid = true;
        }

        public ApplicationSignal[] Applications { get; private set; }

        public class ApplicationSignal
        {
            public int ApplicationType { get; internal set; }
            public int AitVersionNumber { get; internal set; }
        }
    }
}
