package com.agilex.healthcare.schedulingmanager.linkbuilder;

import java.net.URI;

import javax.ws.rs.core.UriBuilder;

import com.agilex.healthcare.mobilehealthplatform.domain.PatientIdentifier;
import com.agilex.healthcare.schedulingmanager.domain.SMPatientPreference;
import com.agilex.healthcare.utility.NullChecker;

public class PatientPreferencesLinkBuilder {
	private URI baseUri;

	public PatientPreferencesLinkBuilder(URI baseUri) {
		UriDtoValidator.validate(baseUri, "BaseUri is required in order to create patient data links.");
		this.baseUri = baseUri;
	}

	public SMPatientPreference fillLinks(SMPatientPreference pref, URI requestUri) {
		if(pref !=null) {
			UriHelper.setSelfUri(pref, requestUri, getCannonicalSelfUri(pref));
		}
		return pref;
	}

	protected URI getBaseUri() {
		return this.baseUri;
	}
	
//	protected URI extractPatientUri(PatientPreference pref) {
//		return PatientUriHelper.createPatientSelfUri(pref.getPatientIdentifier(), baseUri);
//	}

	protected URI getCannonicalSelfUri(SMPatientPreference perf) {
		return UriBuilder.fromUri(createPatientSelfUri(perf.getPatientIdentifier(), baseUri)).path("preference").build();
	}

    public URI createPatientSelfUri(PatientIdentifier patientIdentifier, URI baseUri) {
        URI uri = null;
        if (patientIdentifier != null) {
            uri = null;
            if (NullChecker.isNotNullish(patientIdentifier.getUniqueId()) && NullChecker.isNotNullish(patientIdentifier.getAssigningAuthority())) {
                uri = UriBuilder.fromUri(baseUri).path("patient").path(patientIdentifier.getAssigningAuthority()).path(patientIdentifier.getUniqueId()).build();
            }
        }
        return uri;
    }
	
}
