package fr.insa.clavardator.client.users;

import fr.insa.clavardator.client.server.proxy.Proxy;
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 ProxyPeerConnection extends PeerConnection {
	private final Proxy proxy;
	private final String userId;

	public ProxyPeerConnection(Proxy proxy, String userId) {
		this.proxy = proxy;
		this.userId = userId;
	}

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


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

	@Override
	public void disconnect() {
		proxy.disconnectUser(userId);
	}
}
