package com.agilex.healthcare.schedulingmanager.linkbuilder;

import com.agilex.healthcare.mobilehealthplatform.domain.AtomLink;
import com.agilex.healthcare.mobilehealthplatform.domain.LinkTitles;
import com.agilex.healthcare.mobilehealthplatform.domain.ResourceDirectory;
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 LocationServiceResourceDirectoryBuilder {

	public LocationServiceResourceDirectoryBuilder() {
	}

	public ResourceDirectory getResourceDirectory(URI systemBaseUri, String facilityCode) {

		ResourceDirectory directory = new ResourceDirectory();
		AtomLink link;

		link = new AtomLink();
		link.setHref(UriBuilder.fromUri(systemBaseUri).path("location-service").path("site").path(facilityCode).path("resource-directory").build());
		link.setTitle("resource-directory");
		directory.getLink().setSelfLink(link);

//		link = new AtomLink();
//		link.setHref(UriBuilder.fromUri(systemBaseUri).path("location-service").path("site").path(facilityCode).path("wards").build());
//		link.setTitle(LinkTitles.WardsOperationalScope);
//		link.setType(MediaType.APPLICATION_XML);
//		directory.getLink().add(link);

		link = new AtomLink();
		link.setHref(UriBuilder.fromUri(systemBaseUri).path("location-service").path("site").path(facilityCode).path("clinics").build());
		link.setTitle(LinkTitles.ClinicsOperationalScope);
		link.setType(MediaType.APPLICATION_XML);
		directory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(systemBaseUri).path("location-service").path("site").path(facilityCode).path("specialties").build());
        link.setTitle(LinkTitles.SpecialtiesOperationalScope);
        link.setType(MediaType.APPLICATION_XML);
        directory.getLink().add(link);

//        link = new AtomLink();
//        link.setHref(UriBuilder.fromUri(systemBaseUri).path("location-service").path("site").path(facilityCode).path("specialties").path("system").path(DataSourceSystem.CDW.toString()).build());
//        link.setTitle(LinkTitles.SchedulingSpecialties);
//        link.setType(MediaType.APPLICATION_XML);
//        directory.getLink().add(link);

        link = new AtomLink();
        link.setHref(UriBuilder.fromUri(systemBaseUri).path("location-service").path("site").path(facilityCode).path("specialty").build());
        link.setTitle(LinkTitles.SpecialtyOperationalScope);
        link.setType(MediaType.APPLICATION_XML);
        directory.getLink().add(link);

        return directory;
	}

}