package com.agilex.healthcare.schedulingmanager.linkbuilder;


import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentRequestMessage;
import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentRequestMessages;

import javax.ws.rs.core.UriBuilder;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;

public class AppointmentRequestMessagesLinkBuilder extends PatientDataLinkBuilder<SMAppointmentRequestMessages, SMAppointmentRequestMessage> {

    public AppointmentRequestMessagesLinkBuilder(URI baseUri) {
        super(baseUri);
    }

    @Override
    public URI getCannonicalSelfUri(SMAppointmentRequestMessage dataItem) {
        String encodedUserId = encode(dataItem.getPatientId());
        String encodedAppointmentRequestId = encode(dataItem.getAppointmentRequestId());
        URI selfUri = UriBuilder.fromUri(getBaseUri()).path("appointment-service").path("patient").path(dataItem.getPatientIdentifier().getAssigningAuthority())
                .path(encodedUserId).path("appointment-requests").path("system").path(dataItem.getDataIdentifier().getSystemId()).path("id").path(encodedAppointmentRequestId).path("messages").build();

        return selfUri;

    }

    private String encode(String id) {
        String encoded;
        try {
            encoded = URLEncoder.encode(id, "UTF-8");
        } catch (UnsupportedEncodingException failedToEncode) {
            throw new RuntimeException("Could not encode a URL parameter for SMAppointmentRequests");
        }
        return encoded;
    }

    @Override
    public URI getCannonicalUriForCollection(URI patientUri) {
        return null;
    }

    @Override
    protected void fillCustomRelatedLinks(SMAppointmentRequestMessage dataItem) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    protected void fillCustomRelatedLinks(SMAppointmentRequestMessages dataList) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

}