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.Dvb.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x44,"NIT")]
    [BannedTable("PMT")]
    public class CableDeliverySystemDescriptor : TsDescriptor
    {
        public CableDeliverySystemDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            Frequency = ms.ReadUInt32BE();
            FecOuter = (OuterFecScheme)(ms.ReadUInt16BE() & 0x000f);
            Modulation = (ms.ReadUInt8());

            uint readUInt32Be = ms.ReadUInt32BE();
            SymbolRate = ((readUInt32Be & 0xfffffff0) >> 4).UnpackBcd();
            FecInner = ((SatelliteDeliverySystemDescriptor.InnerFecScheme)(readUInt32Be & 0x0000000f));
        }

        public byte Modulation { get; private set; }

        public SatelliteDeliverySystemDescriptor.InnerFecScheme FecInner { get; private set; }

        public long SymbolRate { get; private set; }

        public OuterFecScheme FecOuter { get; private set; }

        public uint Frequency { get; private set; }

        public enum OuterFecScheme : ushort
        {
            NotDefined = 0,
            NoOuterFec = 1,
            ReedSolomon204_188 = 2
        }
    }
}
