package be.iminds.ilabt.jfed.util;

import be.iminds.ilabt.jfed.lowlevel.connection.JFedConnection;

import javax.annotation.Nonnull;
import javax.net.SocketFactory;
import java.io.IOException;
import java.net.SocketImplFactory;

/**
 * User: twalcari
 * Date: 5/24/2016
 * Time: 16:57
 */
public class SshProxySocketFactory extends SshProxySocketImplFactory.SocketFactoryWithCustomSocketImplFactory {
    private SshProxySocketFactory(SocketImplFactory socketImplFactory) {
        super(socketImplFactory);
    }

    public static SshProxySocketFactory create(@Nonnull JFedConnection.SshProxyInfo sshProxyInfo) throws IOException {
        return new SshProxySocketFactory(SshProxySocketImplFactory.getFactory(sshProxyInfo));
    }

    public static SshProxySocketFactory create(@Nonnull JFedConnection.SshProxyInfo sshProxyInfo, SocketFactory customSocketFactory) throws IOException {
        return new SshProxySocketFactory(SshProxySocketImplFactory.getFactory(sshProxyInfo, customSocketFactory));
    }

    public static SshProxySocketFactory createWithForcedTarget(@Nonnull JFedConnection.SshProxyInfo sshProxyInfo,
                                                       @Nonnull String targetHostname, int targetPort) throws IOException {
        return new SshProxySocketFactory(SshProxySocketImplFactory.getFactory(sshProxyInfo, targetHostname, targetPort));
    }

    public static SshProxySocketFactory createWithForcedTarget(@Nonnull JFedConnection.SshProxyInfo sshProxyInfo, SocketFactory customSocketFactory,
                                                               @Nonnull String targetHostname, int targetPort) throws IOException {
        return new SshProxySocketFactory(SshProxySocketImplFactory.getFactory(sshProxyInfo, customSocketFactory, targetHostname, targetPort));
    }
}
