using System;

namespace QCRPG.Framework;

public class ConnectionBase : IObserver<OutgoingPacketData>
{
	protected GenericNotifier<ConnectionStateChangeInfo> connectionStateChangeInfoNotifier = new GenericNotifier<ConnectionStateChangeInfo>();

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

	public void RegisterConnectionStateChangeInfoObserver(IObserver<ConnectionStateChangeInfo> observer)
	{
		connectionStateChangeInfoNotifier.RegisterObserver(observer);
	}

	public void UnregisterConnectionStateChangeInfoObserver(IObserver<ConnectionStateChangeInfo> observer)
	{
		connectionStateChangeInfoNotifier.UnregisterObserver(observer);
	}

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

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

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

	public virtual void Close()
	{
	}

	public virtual bool IsOpen()
	{
		return false;
	}

	public virtual void Send(OutgoingPacketData packetData)
	{
		throw new Exception("The connection is closed");
	}
}
