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

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.entity.onl.security.CryptoModuleConfig;
import com.eactive.eai.data.entity.onl.security.QCryptoModuleConfig;
import com.eactive.eai.data.jpa.AbstractDataService;
import com.querydsl.core.types.dsl.BooleanExpression;

@Service
@Transactional
public class CryptoModuleConfigDataServiceImpl
		extends AbstractDataService<CryptoModuleConfig, String, CryptoModuleConfigRepository>
		implements CryptoModuleConfigDataService {

	@Override
	public Page<CryptoModuleConfig> findAll(Pageable pageable, String searchName, String algType,
			String keySourceType, String useYn) {
		QCryptoModuleConfig q = QCryptoModuleConfig.cryptoModuleConfig;

		BooleanExpression predicate = q.cryptoName.containsIgnoreCase(searchName != null ? searchName : "");

		if (algType != null && !algType.isEmpty()) {
			predicate = predicate.and(q.algType.eq(algType));
		}
		if (keySourceType != null && !keySourceType.isEmpty()) {
			predicate = predicate.and(q.keySourceType.eq(keySourceType));
		}
		if (useYn != null && !useYn.isEmpty()) {
			predicate = predicate.and(q.useYn.eq(useYn));
		}

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