package com.eactive.eai.rms.data.entity.onl.adapter;

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 com.eactive.eai.data.jpa.AbstractDataService;
import com.eactive.eai.rms.common.comDomain.CommonDomainUI;
import com.querydsl.core.types.dsl.BooleanExpression;

@Service
@Transactional
public class CommonDomainService extends AbstractDataService<CommonDomain, String, CommonDomainRepository> {

	public Page<CommonDomain> findAll(Pageable pageable, CommonDomainUI commonDomainUI) {
		QCommonDomain qCommonDomain = QCommonDomain.commonDomain;
		BooleanExpression predicate = qCommonDomain.domainNm.containsIgnoreCase(commonDomainUI.getSearchDomainNM());

		if (StringUtils.isNotBlank(commonDomainUI.getSearchDomType())) {
			predicate = predicate.and(qCommonDomain.domainType.eq(commonDomainUI.getSearchDomType()));
		}
		if (StringUtils.isNotBlank(commonDomainUI.getSearchDomOpt())) {
			predicate = predicate.and(qCommonDomain.domainOption.eq(commonDomainUI.getSearchDomOpt()));
		}
		return repository.findAll(predicate, pageable);
	}

}
