package eu.eudat.logic.mapper.elastic.criteria;

import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.entities.Grant;
import eu.eudat.elastic.criteria.DmpCriteria;

import java.util.UUID;
import java.util.stream.Collectors;

public class DmpCriteriaMapper {

	public static DmpCriteria toElasticCriteria(DataManagementPlanCriteria criteria) {
		DmpCriteria elastic = new DmpCriteria();

		elastic.setAllowAllVersions(criteria.getAllVersions());
		elastic.setCollaborators(criteria.getCollaborators());
		if (criteria.getGrants() != null) {
			elastic.setGrants(criteria.getGrants().stream().map(Grant::getId).collect(Collectors.toList()));
		}
		elastic.setGroupIds(criteria.getGroupIds());
		elastic.setLike(criteria.getLike());
		if (criteria.getOrganisations() != null) {
			elastic.setOrganizations(criteria.getOrganisations().stream().map(UUID::fromString).collect(Collectors.toList()));
		}
		elastic.setPublic(criteria.getIsPublic());
		if (criteria.getStatus() != null) {
			elastic.setStatus(criteria.getStatus().shortValue());
		}
		elastic.setTemplates(criteria.getDatasetTemplates());
		elastic.setGrantStatus(criteria.getGrantStatus());
		return elastic;
	}
}
