package eu.dnetlib.contract.similarity.mocks;

import java.util.List;

import javax.xml.ws.wsaddressing.W3CEndpointReference;

import eu.dnetlib.common.profile.ProfileHeader;
import eu.dnetlib.contract.utils.FileUtils;
import eu.dnetlib.data.information.similarity.SimilarityServiceConstants;
import eu.dnetlib.data.information.similarity.profile.SimilarityBody;
import eu.dnetlib.data.information.similarity.profile.SimilarityProfileMarshaller;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.miscutils.datetime.DateUtils;

/**
 * IS LookUp mock used for testing blackboard related contracts.
 * 
 * @author mhorst
 *
 */
public class ISLookUpMock implements ISLookUpService {

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

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

	@Override
	public String getResourceProfile(String arg0) throws ISLookUpException,
			ISLookUpDocumentNotFoundException {
		if (isAccessingAlreadyCreatedByMockResource(arg0)) {
//			resource was created by IS-PR, returning SimilarityDS profile
			ProfileHeader profileHeader = new ProfileHeader(arg0,
					SimilarityServiceConstants.SIMILARITY_DS_RESOURCE_TYPE,
					SimilarityServiceConstants.SIMILARITY_DS_RESOURCE_KIND);
			SimilarityBody profileBody = new SimilarityBody();
			profileBody.setLastUpdate(DateUtils.now_ISO8601());
			profileBody.setStored(0);
			profileBody.setMetaDataFormat("oai_dc");
			profileBody.setMetaDataFormatLayout("index");
			return SimilarityProfileMarshaller.generateSimilarityProfile(
					profileHeader, profileBody);
			
		} else {
			throw new ISLookUpDocumentNotFoundException("always not found!");
		}
	}

	protected boolean isAccessingAlreadyCreatedByMockResource(String query) {
		return (query!=null && query.contains(
				ISRegistryMock.PREDEFINED_IS_PR_PROF_PREFIX));
	}
	
	@Override
	public String getResourceProfileByQuery(String arg0)
			throws ISLookUpException, ISLookUpDocumentNotFoundException {
		if (arg0.contains("/DRIVER/MDFormatDSResources/MDFormatDSResourceType")) {
			try {
				return FileUtils.getFileContent(
						"classpath:eu/dnetlib/contract/similarity/mocks/" +
						"predefinedMDFormatProfile.xml");
			} catch (Exception e) {
				throw new ISLookUpException(e);
			}
		} else {
			throw new ISLookUpDocumentNotFoundException(
					"not found if not MDFormat resource!");
		}
	}
	
	@Override
	public String getResourceQoSParams(String arg0) throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

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

	@Override
	public W3CEndpointReference listCollections(String arg0, String arg1,
			String arg2) throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public W3CEndpointReference listCommunities() throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

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

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

	@Override
	public W3CEndpointReference listResourceProfiles(String arg0, String arg1,
			String arg2) throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

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

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

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

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

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

	@Override
	public W3CEndpointReference searchProfile(String arg0)
			throws ISLookUpException {
		// 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

	}

}
