package eu.dnetlib.contract.similarity.mocks;

import java.util.List;

import org.apache.log4j.Logger;

import eu.dnetlib.contract.utils.ITestSleeperClient;
import eu.dnetlib.enabling.is.registry.ISRegistryDocumentNotFoundException;
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;

/**
 * IS Registry mock used for testing blackboard related contracts.
 * 
 * @author mhorst
 *
 */
public class ISRegistryMock implements ISRegistryService, ITestSleeperClient {

	public static final String PREDEFINED_IS_PR_PROF_PREFIX = "mock_id_";
	
	protected final Logger log = Logger.getLogger(this.getClass()); 
	
	/**
	 * Aux flag to determining if FEEDing phase has finished.
	 */
	protected boolean feedingFinished = false;
	
	@Override
	public void addBlackBoardMessage(String arg0, String arg1, String arg2)
			throws ISRegistryException {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean addOrUpdateResourceType(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean addProfileNode(String arg0, String arg1, String arg2)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean addResourceType(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void deleteBlackBoardMessage(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean deleteProfile(String arg0) throws ISRegistryException,
			ISRegistryDocumentNotFoundException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteProfiles(List<String> arg0) throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteResourceType(String arg0, Boolean arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean executeXUpdate(String arg0) throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String insertProfileForValidation(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String invalidateProfile(String arg0) throws ISRegistryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean refreshProfile(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String registerProfile(String arg0) throws ISRegistryException {
		log.info("registering profile: " + arg0);
		return PREDEFINED_IS_PR_PROF_PREFIX + System.currentTimeMillis();
	}

	@Override
	public String registerSecureProfile(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean removeProfileNode(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void replyBlackBoardMessage(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		log.info("got reply BB message: " + arg1);
		if (checkIfFeedingFinished(arg1)) {
			feedingFinished = true;
			log.info("feeding finished!!!");
		}
	}

	boolean checkIfFeedingFinished(String message) {
		return (message.contains("FEED") 
				&& (message.contains("DONE") || message.contains("FAILED")));
		
	}
	
	@Override
	public boolean updateProfile(String arg0, String arg1, String arg2)
			throws ISRegistryException {
		log.info("updating profile: "+arg0+" with content: " + arg1);
		return true;
	}

	@Override
	public String updateProfileDHN(String arg0) throws ISRegistryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean updateProfileNode(String arg0, String arg1, String arg2)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateRegionDescription(String arg0, String arg1)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String validateProfile(String arg0) throws ISRegistryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<String> validateProfiles(List<String> arg0)
			throws ISRegistryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String identify() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void notify(String arg0, String arg1, String arg2, String arg3) {
		// TODO Auto-generated method stub

	}

	@Override
	public void start() {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.contract.utils.ITestSleeperClient#isProcessingFinished()
	 */
	public boolean isProcessingFinished() {
		return feedingFinished;
	}

}
