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

import com.agilex.healthcare.mobilehealthplatform.domain.filter.datefilter.DateFilter;
import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentRequest;
import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentRequestMessage;
import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentRequestMessages;
import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentRequests;

import java.util.HashMap;

public class AppointmentRequestDataLayerRepo implements AppointmentRequestDataLayer {
	
	private static final org.apache.commons.logging.Log LOGGER = org.apache.commons.logging.LogFactory.getLog(AppointmentRequestDataLayerRepo.class);

//	@Resource
	private AppointmentRequestDao AppointmentRequestDao;

    public AppointmentRequestDataLayerRepo() {
    }

    public AppointmentRequestDataLayerRepo(AppointmentRequestDao AppointmentRequestDao) {
        this.AppointmentRequestDao = AppointmentRequestDao;
    }

    @Override
	public SMAppointmentRequests fetchAppointmentRequestsByPatient(String patientId, DateFilter filter) {
		LOGGER.debug(String.format("Getting SMAppointmentRequest with [patientId: %s]", patientId));
		return AppointmentRequestDao.getActiveAppointmentRequests(patientId, filter);
	}

	public SMAppointmentRequest saveAppointmentRequest(SMAppointmentRequest SMAppointmentRequest) {
		LOGGER.debug(String.format("Saving SMAppointmentRequest with [id: %s][patientId: %s]", SMAppointmentRequest.getUniqueId(), SMAppointmentRequest.getPatientId()));
		return AppointmentRequestDao.saveAppointmentRequest(SMAppointmentRequest);
	}

	public void deleteAppointmentRequest(SMAppointmentRequest SMAppointmentRequest) {
		LOGGER.debug(String.format("Deleting SMAppointmentRequest with [id: %s]", SMAppointmentRequest.getUniqueId()));
		AppointmentRequestDao.deleteAppointmentRequest(SMAppointmentRequest);
	}

	@Override
	public SMAppointmentRequest fetchAppointmentRequest(String patientId, String appointmentRequestId) {
		LOGGER.debug(String.format("Getting Filtered SMAppointmentRequests [AppointmentRequestId: %s] [PatientId: %s]", appointmentRequestId, patientId));
		return AppointmentRequestDao.getActiveAppointmentRequest(patientId, appointmentRequestId);
	}

    @Override
    public SMAppointmentRequestMessages fetchAppointmentRequestMessages(String patientId, String appointmentRequestId) {
    	LOGGER.debug(String.format("Getting SMAppointmentRequestMessages for [AppointmentRequestId: %s] [PatientId: %s]", appointmentRequestId, patientId));
    	return AppointmentRequestDao.getAppointmentRequestMessagesByAppointmentRequestId(patientId, appointmentRequestId);
    }

    @Override
    public SMAppointmentRequestMessage saveAppointmentRequestMessage(String patientId, SMAppointmentRequestMessage smAppointmentRequestMessage, boolean isProvider) {
    	LOGGER.debug(String.format("Saving SMAppointmentRequestMessage "));
		
		return AppointmentRequestDao.saveAppointmentRequestMessage(patientId, smAppointmentRequestMessage, isProvider);
    }

    @Override
	public SMAppointmentRequests fetchAppointmentRequests(AppointmentRequestFilter filter) {
		LOGGER.debug(String.format("Getting SMAppointmentRequest with [Filter: %s]", filter));
		return AppointmentRequestDao.getAppointmentRequests(filter);
	}

	@Override
	public SMAppointmentRequest updateMessageFlag(String patientId, String appointmentRequestId, boolean isProvider) {
		LOGGER.debug("Updating message flag for Appointment Request Id = " + appointmentRequestId + " PatientId = " + patientId + " IsProvider = " + isProvider);
		return AppointmentRequestDao.updateAppointmentRequestMessageFlag(patientId, appointmentRequestId, isProvider);
	}

	@Override
	public SMAppointmentRequest markAppointmentRequestIsSeenByProvider(String patientId, String appointmentRequestId) {
		LOGGER.debug("Updating Provider_Seen_Appointment_Request flag for Appointment Request Id = " + appointmentRequestId + " PatientId = " + patientId);
		return AppointmentRequestDao.updateProviderSeenAppointmentRequestFlag(patientId, appointmentRequestId);
	}

    @Override
    public SMAppointmentRequests fetchAppointmentRequests(AppointmentRequestFilter filter, boolean freshStart, HashMap<String, Boolean> sortFields, String filterString, int  firstRecord, int  lastRecord) {
        return AppointmentRequestDao.getAppointmentRequests(filter, freshStart, sortFields, filterString, firstRecord, lastRecord);
    }
}
