using System;
using System.IO;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.DsmCc.Descriptors
{
    [SkyscraperPlugin]
    [TsDescriptor(0x13,"PMT")]
    [BannedTable("BAT","TSDT")]
    class CarouselIdentifierDescriptor : TsDescriptor
    {
        public CarouselIdentifierDescriptor(byte[] buffer)
        {
            if (buffer.Length < 5)
                return;

            MemoryStream ms = new MemoryStream(buffer, false);
            CarouselId = ms.ReadUInt32BE();
            FormatId = ms.ReadUInt8();
            switch (FormatId)
            {
                case 0:
                    break;
                case 1:
                    FormatSpecifier = new FormatSpecifier(ms);
                    break;
                default:
                    throw new NotImplementedException(String.Format("Carousel format {0:X2}", FormatId));
            }

            Valid = true;
        }

        public byte FormatId { get; private set; }

        public uint CarouselId { get; private set; }
        public FormatSpecifier FormatSpecifier { get; }
    }
}
