using skyscraper5.Dvb.Psi;
using skyscraper5.Dvb.Psi.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper8.DvbSis
{
    public class SisNitContainer : INitEventHandler
    {
        public void OnNitNetwork(NitNetwork nitNetwork)
        {
            Network = nitNetwork;
        }

        public void OnNitTransportStream(ushort networkId, NitTransportStream transportStream)
        {
            if (_transportStreams == null)
                _transportStreams = new List<Tuple<ushort, NitTransportStream>>();

            _transportStreams.Add(new Tuple<ushort, NitTransportStream> (networkId, transportStream ));
        }

        public void SetNetworkId(ushort networkId, bool forceOverrite = false)
        {
            this.NetworkId = networkId;
        }

        public ushort? NetworkId { get; private set; }
        public NitNetwork Network { get; private set; }

        private List<Tuple<ushort, NitTransportStream>> _transportStreams;

        public IReadOnlyList<Tuple<ushort,NitTransportStream>> TransportStreams
        {
            get
            {
                if (_transportStreams == null)
                    return new List<Tuple<ushort, NitTransportStream>>().AsReadOnly();

                return _transportStreams.AsReadOnly();
            }
        }
    }
}
