package com.eactive.eai.rms.data.entity.onl.apim.portalterms;

import com.eactive.apim.portal.agreements.entity.AgreementType;
import com.eactive.apim.portal.agreements.entity.Agreements;
import com.eactive.apim.portal.agreements.entity.AgreementsId;
import com.eactive.apim.portal.agreements.entity.QAgreements;
import com.eactive.eai.rms.data.jpa.AbstractEMSDataSerivce;
import com.querydsl.core.BooleanBuilder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(transactionManager = "transactionManagerForEMS")
public class PortalTermsService extends AbstractEMSDataSerivce<Agreements, AgreementsId, PortalTermsRepository> {

	public Page<Agreements> findAll(Pageable pageable, String searchAgreementsType) {
		BooleanBuilder predicate = new BooleanBuilder();

		if (StringUtils.isNotBlank(searchAgreementsType)) {
			predicate.and(QAgreements.agreements.agreementsType.eq(AgreementType.valueOf(searchAgreementsType)));
		}

		return repository.findAll(predicate, pageable);
	}
}
