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

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.querydsl.core.types.dsl.BooleanExpression;

@Service
@Transactional
public class ScopeInfoService extends AbstractDataService<ScopeInfo, String, ScopeInfoRepository> {

	public Page<ScopeInfo> findAll(Pageable pageable, ScopeSearch scopeSearch) {
		QScopeInfo qScopeInfo = QScopeInfo.scopeInfo;

		BooleanExpression predicate = qScopeInfo.scopeId.containsIgnoreCase(scopeSearch.getSearchScopeId());

		if (StringUtils.isNotBlank(scopeSearch.getSearchScopeName())) {
			predicate = predicate.and(qScopeInfo.scopeName.containsIgnoreCase(scopeSearch.getSearchScopeName()));
		}
		return repository.findAll(predicate, pageable);
	}

}
