namespace QCRPG.Framework;

public class ProtocolBase : IObserver<OutgoingPacketData>, IObserver<IncomingPacketData>
{
	protected GenericNotifier<OutgoingPacketData> sendDataNotifier = new GenericNotifier<OutgoingPacketData>();

	protected GenericNotifier<IncomingPacketData> receiveDataNotifier = new GenericNotifier<IncomingPacketData>();

	public virtual bool ReceiveStateIsNewPacket => true;

	public void RegisterSendDataObserver(IObserver<OutgoingPacketData> observer)
	{
		sendDataNotifier.RegisterObserver(observer);
	}

	public void UnregisterSendDataObserver(IObserver<OutgoingPacketData> observer)
	{
		sendDataNotifier.UnregisterObserver(observer);
	}

	public void RegisterReceiveDataObserver(IObserver<IncomingPacketData> observer)
	{
		receiveDataNotifier.RegisterObserver(observer);
	}

	public void UnregisterReceiveDataObserver(IObserver<IncomingPacketData> observer)
	{
		receiveDataNotifier.UnregisterObserver(observer);
	}

	public virtual void Send(OutgoingPacketData packetData)
	{
		sendDataNotifier.NotifyObservers(packetData);
	}

	public void NotifyObserver(OutgoingPacketData packetData)
	{
		Send(packetData);
	}

	public virtual void NotifyObserver(IncomingPacketData packetData)
	{
		receiveDataNotifier.NotifyObservers(packetData);
	}
}
