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

import com.eactive.apim.portal.portalfaq.entity.PortalFaq;
import com.eactive.apim.portal.portalfaq.entity.QPortalFaq;
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 PortalFaqService extends AbstractEMSDataSerivce<PortalFaq, String, PortalFaqRepository> {

	public Page<PortalFaq> findAll(Pageable pageable, PortalFaqSearch portalFaqSearch) {
		QPortalFaq qPortalFaq = QPortalFaq.portalFaq;

		BooleanBuilder predicate = new BooleanBuilder();

		if (StringUtils.isNotBlank(portalFaqSearch.getSearchUseYn())) {
			predicate.and(qPortalFaq.useYn.eq(portalFaqSearch.getSearchUseYn()));
		}

		if (StringUtils.isNotBlank(portalFaqSearch.getSearchSubjectDetail())) {
			predicate.and(qPortalFaq.faqQuestion.containsIgnoreCase(portalFaqSearch.getSearchSubjectDetail())
					.or(qPortalFaq.faqAnswer.containsIgnoreCase(portalFaqSearch.getSearchSubjectDetail())));
		}

		return repository.findAll(predicate, pageable);
	}

}