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

namespace skyscraper5.Dvb.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x5f,"NIT","BAT","SDT","EIT","PMT", "Astra SGT")]
    [BannedTable("CAT")]    // <-- Scientific Atlanta is known to put private_data_specifier_descriptors into the CAT, however this is a private extension.
    public class PrivateDataSpecifierDescriptor : TsDescriptor
    {
        public PrivateDataSpecifierDescriptor(byte[] buffer)
        {
            if (buffer.Length != 4)
            {
                Valid = false;
                return;
            }

            if (BitConverter.IsLittleEndian)
				Array.Reverse(buffer);
            PrivateDataSpecifier = BitConverter.ToUInt32(buffer, 0);
        }

        public PrivateDataSpecifierDescriptor(uint value)
        {
	        PrivateDataSpecifier = value;
        }

        public uint PrivateDataSpecifier { get; private set; }

        public override byte[] Serialize()
        {
	        byte[] bytes = BitConverter.GetBytes(PrivateDataSpecifier);
	        if (BitConverter.IsLittleEndian)
		        Array.Reverse(bytes);
	        return bytes;
        }
    }
}
