package utils;

import infoObjects.InfoError;
import infoObjects.InfoResults;
import infoObjects.InfoTarea;
import infoObjects.InfoTest;
import interfaces.InterfaceSecurity;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;



public class RMIServices  implements ConstantsErr {
	
	static InterfaceSecurity interfaceSecurity = null;
	
	public static void connectRMI() throws MalformedURLException, RemoteException, NotBoundException{
		//if (System.getSecurityManager() == null)
	            //System.setSecurityManager ( new SecurityManager() );
        String url = "rmi://127.0.1.1:1099/SecuritySCP";
        System.err.println("Xivato 1 url: "+url);
        interfaceSecurity = (InterfaceSecurity) Naming.lookup(url);
	}

	public static boolean isConnected(){
		if (interfaceSecurity != null){
			return true;
		}
		return false;
	}
	
	public void setShowHelpDebug(boolean show) throws RemoteException{
		interfaceSecurity.setShowHelpDebug(show);
	}
	
	public static InfoError securityCheckCode(InfoTarea infoTarea) throws RemoteException {

		return interfaceSecurity.securityCheckCode(infoTarea);
	}

	public static InfoError securityNewTask(InfoTarea infoTarea) throws RemoteException {

		return interfaceSecurity.securityNewTask(infoTarea);
	}

	public static InfoError securityRunTest(InfoTest infoTest) throws RemoteException {
		return interfaceSecurity.securityRunTest(infoTest);
	}

	public static InfoError securitySaveTest(InfoTest infoTest) throws RemoteException {
		return interfaceSecurity.securitySaveTest(infoTest);
	}
	
	public static InfoError securityDeleteTest(InfoTest infoTest) throws RemoteException {
		return interfaceSecurity.securityDeleteTest(infoTest);
	}
	
	public static InfoError securityDeleteTask(InfoTarea infoTarea) throws RemoteException {
		return interfaceSecurity.securityDeleteTask(infoTarea);
	}
	
	public static InfoResults securityStudentRunTask(InfoTarea infoTarea) throws RemoteException{
		return interfaceSecurity.securityStudentRunTask(infoTarea);
	}
	
	public static InfoError securityCleanData() throws RemoteException{
		return interfaceSecurity.securityCleanData();
	}
	
}
