package be.iminds.ilabt.jfed.lowlevel.connection;

import be.iminds.ilabt.jfed.lowlevel.JFedException;
import org.apache.xmlrpc.client.XmlRpcClient;

import java.util.List;

/**
 * SfaConnection: an XmlRpc connection (typically over https with or without user authentication or over http without any authentication)
 */
public abstract class SfaConnection extends JFedConnection {
    protected String lastCommand;
    protected List lastArgv;

    protected HttpInfoXmlRpcTransportFactory xmlRpcTransportFactory;
    protected XmlRpcClient xmlRpcClient;


    public SfaConnection(ConnectionConfig connectionConfig) throws JFedException {
        super(connectionConfig);
    }

    public HttpInfoXmlRpcTransportFactory getXmlRpcTransportFactory() {
        return xmlRpcTransportFactory;
    }

    public XmlRpcClient getXmlRpcClient() {
        return xmlRpcClient;
    }

    /**
     * remove date about last call stored in connection object
     */
    public void clearLastCallData() {
        if (xmlRpcTransportFactory != null)
            xmlRpcTransportFactory.clearLastCallData();
    }

    /**
     * called by AbstractApi just before calling xmlRpcClient.execute(command, argv)
     *
     * This allows nice logging and processing of the executed command.
     *
     * This is used by MockSfaConnection to match the mock answer
     */
    public void logWillExecuteXmlRpc(String command, List argv) {
        this.lastCommand = command;
        this.lastArgv = argv;
    }
}
