using System;
using Decal.Adapter.Wrappers;

namespace Decal.Adapter;

[CLSCompliant(true)]
public abstract class FilterBase : Extension
{
	private NetServiceHost myHost;

	[CLSCompliant(false)]
	protected NetServiceHost Host => myHost;

	[CLSCompliant(false)]
	protected event EventHandler<NetworkMessageEventArgs> ServerDispatch;

	[CLSCompliant(false)]
	protected event EventHandler<NetworkMessageEventArgs> ClientDispatch;

	protected FilterBase()
		: base(DecalExtensionType.NetworkFilter)
	{
	}

	/// <summary>
	/// Used for internal wiring up of base-class variables.
	/// Called by FilterProxy
	/// </summary>
	/// <param name="newHost">Host (pluginsite) object</param>
	internal void SetHost(NetServiceHost newHost)
	{
		myHost = newHost;
	}

	internal void fireNetwork(Message newMsg, bool Server)
	{
		if (Server && this.ServerDispatch != null)
		{
			this.ServerDispatch(this, new NetworkMessageEventArgs(newMsg));
		}
		else if (!Server && this.ClientDispatch != null)
		{
			this.ClientDispatch(this, new NetworkMessageEventArgs(newMsg));
		}
	}
}
