namespace QCRPG.Framework;

public class GenericObserver<T> : IObserver<T> where T : IDeepCopyable<T>
{
	public delegate void NotifyObserverCallback(T arg);

	private NotifyObserverCallback notifyObserverCallback;

	private GenericNotifier<T> genericNotifier;

	public GenericObserver(NotifyObserverCallback notifyObserverCallback)
	{
		this.notifyObserverCallback = notifyObserverCallback;
	}

	public GenericObserver(GenericNotifier<T> genericNotifier)
	{
		this.genericNotifier = genericNotifier;
	}

	public void NotifyObserver(T arg)
	{
		if (notifyObserverCallback != null)
		{
			notifyObserverCallback(arg);
		}
		else
		{
			genericNotifier.NotifyObservers(arg);
		}
	}
}
