package com.agilex.healthcare.schedulingmanager.dataservice;

//import com.agilex.healthcare.schedulingmanager.datalayer.facility.FacilityFilter;
//import com.agilex.healthcare.schedulingmanager.datalayer.facility.FacilityFilterFactory;
//import com.agilex.healthcare.schedulingmanager.domain.SchedulingFacilities;
//import com.agilex.healthcare.schedulingmanager.domain.SchedulingFacility;
//import com.agilex.healthcare.utility.NullChecker;
//
//import javax.ws.rs.WebApplicationException;
//import javax.ws.rs.core.Response.Status;
//import java.util.List;

public class FacilityDataService {

//	private Router router;
//
//	public FacilityDataService() {
//		router = new Router();
//	}
//
//	public FacilityDataService(Router router) {
//		this.router = router;
//	}
//
//	public SchedulingFacilities fetchFacilities(FacilityFilter facilityFilter) {
//		return fetchFacilities(facilityFilter,true);
//	}
//
//	public SchedulingFacilities fetchFacilities(FacilityFilter facilityFilter, boolean useCache) {
//		RequestMessage request = FacilityRequestBuilder.forFacilities().forFilter(facilityFilter).build();
//
//		SchedulingFacilities facilities = null;
//		if (useCache) {
//			facilities = FacilityCache.getInstance().getFacilities(facilityFilter);
//			if (facilities == null) {
//				facilities = getFacilitiesFromRouter(request);
//				FacilityCache.getInstance().addFacilitiesToCache(facilityFilter,facilities);
//			}
//		} else {
//			facilities = getFacilitiesFromRouter(request);
//		}
//		return facilities;
//	}
//
//	private SchedulingFacilities getFacilitiesFromRouter(RequestMessage request) {
//		ResponseMessage responseMessage = router.execute(request);
//		return FacilityResponseReader.fromResponse(responseMessage).getFacilities();
//	}
//
//	public SchedulingFacility fetchFacilityByCode(List<String> pilotSites, String code) {
//		return fetchIndividualFacility(pilotSites, code, null);
//	}
//
//
//	public SchedulingFacility fetchFacilityByName(List<String> pilotSites, String name) {
//		return fetchIndividualFacility(pilotSites, null, name);
//	}
//
//
//	private SchedulingFacility fetchIndividualFacility(List<String> pilotSites, String code, String name) {
//		FacilityFilterFactory facilityFilterFactory = new FacilityFilterFactory(pilotSites);
//		FacilityFilter filter = facilityFilterFactory.createEmptyFacilityFilter();
//		if (NullChecker.isNotNullish(code)) {
//			filter.addFacilityCode(code);
//		}
//		if (NullChecker.isNotNullish(name)) {
//			filter.setFacilityName(name);
//		}
//		SchedulingFacilities facilities = fetchFacilities(filter);
//		if (facilities.size() == 0) {
//			throw new WebApplicationException(Status.NOT_FOUND);
//		} else if (facilities.size() > 1) {
//			throw new WebApplicationException(Status.PRECONDITION_FAILED);
//		}
//
//		return facilities.get(0);
//	}
}
