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(0x6d,"NIT")]
    [BannedTable("TSDT")]
    public class CellFrequencyLinkDescriptor : TsDescriptor
    {
        public CellFrequencyLinkDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            while (ms.GetAvailableBytes() >= 7)
            {
                Cell child = new Cell();
                child.CellId = ms.ReadUInt16BE();
                child.Frequency = ms.ReadUInt32BE();
                byte subcellInfoLoopLength = ms.ReadUInt8();
                if (subcellInfoLoopLength > 0)
                {
                    throw new NotImplementedException("subcellInfoLoop");
                }

                if (Cells == null)
                {
                    Cells = new List<Cell>();
                }

                Cells.Add(child);
            }
        }

        public List<Cell> Cells { get; private set; }

        public class Cell
        {
            public ushort CellId { get; internal set; }
            public uint Frequency { get; internal set; }
        }
    }
}
