using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Dvb.DataBroadcasting.DataCarouselDescriptors;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.Mhp.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x10,"AIT")]
    class ApplicationStorageDescriptor : TsDescriptor
    {
        public ApplicationStorageDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, true);
            StorageProperty = ms.ReadUInt8();

            byte readUInt8 = ms.ReadUInt8();
            NotLaunchableFromBroadcast = (readUInt8 & 0x80) != 0;
            LaunchableCompletelyFromCache = (readUInt8 & 0x40) != 0;
            IsLaunchableFromOlderVersion = (readUInt8 & 0x20) != 0;

            Version = ms.ReadUInt32BE() & 0xefffffff;
            Priority = ms.ReadUInt8();
            Valid = true;
        }

        public byte Priority { get; private set; }

        public uint Version { get; private set; }

        public bool IsLaunchableFromOlderVersion { get; private set; }

        public bool LaunchableCompletelyFromCache { get; private set; }

        public bool NotLaunchableFromBroadcast { get; private set; }

        public byte StorageProperty { get; private set; }
    }
}
