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(0x62,"NIT")]
    public class FrequencyListDescriptor : TsDescriptor
    {
        public FrequencyListDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            byte readUInt8 = ms.ReadUInt8();
            CodingType = (CodingTypeValue)(readUInt8 & 0x03);

            long maxI = ms.GetAvailableBytes() / 4;
            CentreFrequencies = new uint[maxI];
            for (int i = 0; i < maxI; i++)
            {
                CentreFrequencies[i] = ms.ReadUInt32BE();
            }
        }

        public uint[] CentreFrequencies { get; private set; }

        public CodingTypeValue CodingType { get; private set; }

        public enum CodingTypeValue
        {
            NotDefined = 0,
            Satellite = 1,
            Cable = 2,
            Terristial = 3
        }
    }
}
