package com.agilex.healthcare.schedulingmanager.dataservice;


import com.agilex.healthcare.schedulingmanager.datalayer.appointment.AppointmentMetricsDataLayer;
import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentMetric;

import javax.annotation.Resource;

public class AppointmentMetricsDataService {

    @Resource
    AppointmentMetricsDataLayer appointmentMetricsDataLayer;

	public AppointmentMetricsDataService() {
	}
	
	public SMAppointmentMetric incrementMetric(String name) {

		SMAppointmentMetric metric = appointmentMetricsDataLayer.getMetric(name);
		
		if (metric != null) {
			metric.setValue(metric.getValue() + 1);
		} else {
			metric = new SMAppointmentMetric();
			metric.setName(name);
			metric.setValue(1);
		}
		
		SMAppointmentMetric result = appointmentMetricsDataLayer.saveMetric(metric);
		
		return result;
	}
}
