package com.agilex.healthcare.schedulingmanager.datalayer.appointment;

import com.agilex.healthcare.schedulingmanager.datalayer.AbstractDao;
import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentMetric;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class AppointmentMetricsDao extends AbstractDao {
	//private static final org.apache.commons.logging.Log LOGGER = org.apache.commons.logging.LogFactory.getLog(AppointmentMetricsDao.class);
	
	public SMAppointmentMetric getAppointmentMetric(String name) {
		AppointmentMetricPo po = this.entityManager.find(AppointmentMetricPo.class, name);
		
		return (po == null) ? null : po.create();
	}
	
	@Transactional(propagation = Propagation.REQUIRED)
	public SMAppointmentMetric saveAppointmentMetric(SMAppointmentMetric metric) {
		AppointmentMetricPo po =  this.entityManager.merge(new AppointmentMetricPo(metric));
		
		return (po == null) ? null : po.create();
	}
	
	@Transactional(propagation = Propagation.REQUIRED)
	public void removeAppointmentMetric(String name) {
		SMAppointmentMetric metricToRemove = getAppointmentMetric(name);
		this.entityManager.remove(new AppointmentMetricPo(metricToRemove));
	}
}
