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.DsmCc.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x1a,"DSM-CC")]
    [BannedTable("TSDT")]
    public class StreamEventDescriptor : TsDescriptor
    {
        public StreamEventDescriptor(byte[] buffer)
        {
            if (buffer.Length < 10)
            {
                Valid = false;
                return;
            }
            MemoryStream ms = new MemoryStream(buffer, false);
            EventId = ms.ReadUInt16BE();
            NptEventSeconds = ms.ReadUInt32BE();
            NptEventMicroseconds = ms.ReadUInt32BE();
            PrivateData = ms.ReadBytes(ms.GetAvailableBytes());
        }

        public byte[] PrivateData { get; private set; }

        public uint NptEventMicroseconds { get; private set; }

        public uint NptEventSeconds { get; private set; }

        public ushort EventId { get; private set; }

        public override string ToString()
        {
            return Encoding.UTF8.GetString(PrivateData);
        }
    }
}
