package com.eactive.eai.rms.data.entity.man.monitoringProperty.service;

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.property.UI.MonitoringPropertyGroupUI;
import com.eactive.eai.rms.data.entity.man.monitoringProperty.MonitoringPropertyGroup;
import com.eactive.eai.rms.data.entity.man.monitoringProperty.QMonitoringPropertyGroup;
import com.eactive.eai.rms.data.entity.man.monitoringProperty.repository.MonitoringPropertyGroupRepository;
import com.querydsl.core.types.dsl.BooleanExpression;

@Service
@Transactional(transactionManager = "transactionManagerForEMS")
public class MonitoringPropertyGroupService
		extends AbstractDataService<MonitoringPropertyGroup, String, MonitoringPropertyGroupRepository> {
	
	public static final String MONITORING_PROPERTY_KEY = "Monitoring";
	
	public static final String MONITORING_PROPERTY_KEY_FORMAT = "Monitoring{%s}";

	public Page<MonitoringPropertyGroup> findAll(Pageable pageable, MonitoringPropertyGroupUI ui) {

		QMonitoringPropertyGroup qMonitoringPropertyGroup = QMonitoringPropertyGroup.monitoringPropertyGroup;

		BooleanExpression predicate = qMonitoringPropertyGroup.prptyGroupName
				.containsIgnoreCase(ui.getSearchPrptyGroupName())
				.and(qMonitoringPropertyGroup.prptyGroupDesc.containsIgnoreCase(ui.getSearchPrptyGroupDesc()));

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