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.IO;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.Mhp.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x05,"AIT")]
    public class ExternalApplicationAuthorisationDescriptor : TsDescriptor
    {
        public ExternalApplicationAuthorisationDescriptor(byte[] buffer)
        {
            Authorisations = new ExternalAuthorization[buffer.Length / 7];
            MemoryStream ms = new MemoryStream(buffer, false);
            for (int i = 0; i < Authorisations.Length; i++)
            {
                ExternalAuthorization child = new ExternalAuthorization();
                Authorisations[i] = child;

                child.OrganisationId = ms.ReadUInt32BE();
                child.ApplicationId = ms.ReadUInt16BE();
                child.ApplicationPriority = ms.ReadUInt8();
            }
            Valid = true;
        }

        public ExternalAuthorization[] Authorisations { get; set; }
        public class ExternalAuthorization
        {
            public uint OrganisationId { get; set; }
            public ushort ApplicationId { get; set; }
            public byte ApplicationPriority { get; set; }
        }
    }
}
