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

import com.eactive.apim.portal.partnershipapplication.entity.PartnershipApplication;
import com.eactive.apim.portal.partnershipapplication.entity.QPartnershipApplication;
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;

import java.util.List;

@Service
@Transactional(transactionManager = "transactionManagerForEMS")
public class PortalPartnershipService extends AbstractEMSDataSerivce<PartnershipApplication, String, PortalPartnershipRepository> {

	public void deleteByIds(List<String> ids) {
		repository.deleteAllById(ids);
	}

	public Page<PartnershipApplication> findAll(Pageable pageable, String searchBizSubject, String searchBizDetail) {
		QPartnershipApplication qPartnershipApplication = QPartnershipApplication.partnershipApplication;

		BooleanBuilder predicate = new BooleanBuilder();

		if (StringUtils.isNotBlank(searchBizSubject)) {
			predicate.and(qPartnershipApplication.bizSubject.containsIgnoreCase(searchBizSubject));
		}
		if (StringUtils.isNotBlank(searchBizDetail)) {
			predicate.and(qPartnershipApplication.bizDetail.containsIgnoreCase(searchBizDetail));
		}

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