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

namespace skyscraper5.src.Mpeg2.PacketFilter
{
	public abstract class BasePacketFilter : IPacketFilter
	{
		public BasePacketFilter()
		{
			_filterEnabled = true;
		}

		/// <summary>
		/// If this is set to false, every packet will be processed further.
		/// If thie is set to true, every packet will be inspected by the implementer.
		/// </summary>
		public bool FilterEnabled => _filterEnabled;
		private bool _filterEnabled;

		public bool PassPacket(TsPacket packet)
		{
			if (!_filterEnabled)
				return true;

			return PassPacketEx(packet);
		}

		/// <summary>
		/// If this returns true, the packet will be put into the next filter. If all filters return true, the packet will be processed.
		/// If this returns false, the packet will be discarded.
		/// </summary>
		/// <returns>Whether to continue processing the packet</returns>
		protected abstract bool PassPacketEx(TsPacket packet);
	}
}
