package fr.insa.clavardator.client.users;

import fr.insa.clavardator.lib.network.TcpConnection;
import fr.insa.clavardator.lib.util.ErrorCallback;
import fr.insa.clavardator.lib.util.SimpleCallback;
import org.jetbrains.annotations.Nullable;

import java.io.Serializable;

public class DirectPeerConnection extends PeerConnection {
	private final TcpConnection connection;

	public DirectPeerConnection(TcpConnection connection) {
		this.connection = connection;
	}

	@Override
	public void send(Serializable message, @Nullable SimpleCallback callback, @Nullable ErrorCallback errorCallback) {
		connection.send(message, callback, errorCallback);
	}


	@Override
	public void receive(TcpConnection.MessageReceivedCallback callback, ErrorCallback errorCallback) {
		connection.receive(callback, errorCallback);
	}


	@Override
	public void disconnect() {
		if (connection != null && connection.isOpen()) {
			connection.close();
		}
	}
}
