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

import com.eactive.eai.data.entity.onl.submessage.QSubMessageInfo;
import com.eactive.eai.data.entity.onl.submessage.SubMessageInfo;
import com.eactive.eai.data.jpa.AbstractDataService;
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.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SubMessageInfoService extends AbstractDataService<SubMessageInfo, String, SubMessageInfoEMSRepository> {

    public Page<SubMessageInfo> findAll(Pageable pageable, String searchBzwkSvcKeyName) {
        QSubMessageInfo qSubMessageInfo = QSubMessageInfo.subMessageInfo;
        BooleanBuilder predicate = new BooleanBuilder();

        if (StringUtils.isNotBlank(searchBzwkSvcKeyName)) {
            predicate.and(qSubMessageInfo.bzwksvckeyname.containsIgnoreCase(searchBzwkSvcKeyName));
        }

        pageable.getSort().and(Sort.by("bzwksvckeyname"));
        return repository.findAll(predicate, pageable);
    }

    public Iterable<SubMessageInfo> findAll(String searchBzwkSvcKeyName) {
        return repository.findAll(QSubMessageInfo.subMessageInfo.bzwksvckeyname.containsIgnoreCase(searchBzwkSvcKeyName));
    }

}
