package com.agilex.healthcare.schedulingmanager.linkbuilder;


import com.agilex.healthcare.mobilehealthplatform.domain.AtomLink;
import com.agilex.healthcare.mobilehealthplatform.domain.ResourceDirectory;
import com.agilex.healthcare.schedulingmanager.domain.SchedulingManagerLinkTitles;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;

@Service
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SchedulingServiceResourceDirectoryBuilder {

    public SchedulingServiceResourceDirectoryBuilder() {
    }

    public ResourceDirectory getResourceDirectory(URI baseUri, URI resourceDirectoryUri, String facilityCode){
        ResourceDirectory resourceDirectory = new ResourceDirectory();
        AtomLink link;

        link = new AtomLink();
        link.setHref(resourceDirectoryUri);
        link.setTitle("resource-directory");
        resourceDirectory.getLink().setSelfLink(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri)
                               .path("scheduling-service")
                               .path("site")
                               .path(facilityCode)
                               .path("waitlist")
                               .path("ewl")
                               .build());
        link.setTitle(SchedulingManagerLinkTitles.FacilityElectronicWaitList);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri)
                               .path("scheduling-service")
                               .path("site")
                               .path(facilityCode)
                               .path("waitlist")
                               .path("near")
                               .build());
        link.setTitle(SchedulingManagerLinkTitles.FacilityNearWaitList);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri)
                               .path("scheduling-service")
                               .path("site")
                               .path(facilityCode)
                               .path("waitlist")
                               .path("recall")
                               .build());
        link.setTitle(SchedulingManagerLinkTitles.FacilityRecallWaitList);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri)
                               .path("scheduling-service")
                               .path("site")
                               .path(facilityCode)
                               .path("purpose-list")
                               .build());
        link.setTitle(SchedulingManagerLinkTitles.BookingPurposeList);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri)
                               .path("scheduling-service")
                               .path("site")
                               .path(facilityCode)
                               .path("waitlist")
                               .path("recall")
                               .build());
        link.setTitle(SchedulingManagerLinkTitles.FacilityRecallWaitList);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri)
                               .path("scheduling-service")
                               .path("site")
                               .path(facilityCode)
                               .path("cancel-reasons-list")
                               .build());
        link.setTitle(SchedulingManagerLinkTitles.CancelReasonsList);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri).path("location-service").path("site").path(facilityCode).path("resource-directory").build());
        link.setTitle(SchedulingManagerLinkTitles.LocationServiceResourceDirectory);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri).path("appointment-service").path("metadata").build());
        link.setType(MediaType.APPLICATION_JSON);
        link.setTitle(SchedulingManagerLinkTitles.AppointmentsMetadata);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri).path("appointment-service").path("appointment-requests").build());
        link.setType(MediaType.APPLICATION_JSON);
        link.setTitle(SchedulingManagerLinkTitles.AppointmentRequests);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri).path("scheduling-service").path("site").path(facilityCode).path("consult").path("services").build());
        link.setType(MediaType.APPLICATION_JSON);
        link.setTitle(SchedulingManagerLinkTitles.ConsultServices);
        resourceDirectory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(baseUri).path("scheduling-service").path("site").path(facilityCode).path("consults").build());
        link.setType(MediaType.APPLICATION_JSON);
        link.setTitle(SchedulingManagerLinkTitles.ConsultsByService);
        resourceDirectory.getLink().add(link);

        return resourceDirectory;
    }




}
