package cz.muni.fi.lasaris.sbms.api;

import java.util.Map;

import javax.annotation.security.PermitAll;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import cz.muni.fi.lasaris.sbms.api.response.TypeResponse;
import cz.muni.fi.lasaris.sbms.model.Fields;
import cz.muni.fi.lasaris.sbms.model.TypesProvider;

@PermitAll
@Path("types")
public class TypesEndpoint {
	
	@GET
	@Path("/type")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getDataPointTypes() {
		return TypesProvider.getDataPointTypes();
	}
	
	@GET
	@Path("/type/{root}")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getDataPointTypes(@PathParam("root") String root) {
		if(root.equals("all")) {
			return TypesProvider.getDataPointTypes();
		} else {
			return TypesProvider.getDataPointTypes(root);
		}
	}
	
	@GET
	@Path("/address.type")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getAddressTypes() {
		return TypesProvider.getAddressTypes();
	}
	
	@GET
	@Path("/address.type/{root}")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getAddressTypes(@PathParam("root") String root) {
		if(root.equals("all")) {
			return TypesProvider.getAllAddressTypes();
		} else {
			return TypesProvider.getAddressTypes(root);
		}
		
	}
	
	@GET
	@Path("/sensing.type")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getSensingTypes() {
		return TypesProvider.getSensingTypes();
	}
	
	@GET
	@Path("/sensing.type/{root}")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getSensingTypes(@PathParam("root") String root) {
		if(root.equals("all")) {
			return TypesProvider.getAllSensingTypes();
		} else {
			return TypesProvider.getSensingTypes(root);
		}
		
	}
	
	@GET
	@Path("/property.quality")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getQualityTypes() {
		return TypesProvider.getQualityTypes();
	}
	
	@GET
	@Path("/influenced.property.quality")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInflQualityTypes() {
		return getQualityTypes();
	}
	
	@GET
	@Path("/property.domain")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getPropDomainTypes() {
		return TypesProvider.getPropDomainTypes();
	}
	
	@GET
	@Path("/influenced.property.domain")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInflPropDomainTypes() {
		return getPropDomainTypes();
	}
	
	@GET
	@Path("/sensing.window")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getTimeWindowTypes() {
		return TypesProvider.getTimeWindowTypes();
	}
	
	@GET
	@Path("/source.type")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getSourceTypes() {
		return TypesProvider.getSourceTypes();
	}
	
	@GET
	@Path("/source.type/{root}")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getSourceTypes(@PathParam("root") String root) {
		if(root.equals("all")) {
			return TypesProvider.getAllSourceTypes();
		} else {
			return TypesProvider.getSourceTypes(root);
		}
		
	}
	
	@GET
	@Path("/scope.type")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getScopeTypes() {
		return TypesProvider.getScopeTypes();
	}
	
	@GET
	@Path("/influenced.scope.type")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInflScopeTypes() {
		return getScopeTypes();
	}
	
	@GET
	@Path("/grouping")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getGroupingTypes() {
		TypeResponse r = new TypeResponse();
		r.setName("grouping");
		r.getMembers().addAll(Fields.GROUPINGS);
		return r;
	}
	
	@GET
	@Path("/field.filter")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getFilterFieldTypes() {
		TypeResponse r = new TypeResponse();
		r.setName("field.filter");
		r.getMembers().addAll(Fields.FILTER_FIELDS);
		return r;
	}
	
	@GET
	@Path("/field.data")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getDataFieldTypes() {
		TypeResponse r = new TypeResponse();
		r.setName("field.data");
		r.getMembers().addAll(Fields.DATA_FIELDS);
		return r;
	}
	
	@GET
	@Path("/field.insert.dataPoint")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInsertFieldTypesDP() {
		TypeResponse r = new TypeResponse();
		r.setName("field.insert.dataPoint");
		r.getMembers().addAll(Fields.INSERT_FIELDS_DP);
		return r;
	}
	
	@GET
	@Path("/field.insert.trend")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInsertFieldTypesTrend() {
		TypeResponse r = new TypeResponse();
		r.setName("field.insert.trend");
		r.getMembers().addAll(Fields.INSERT_FIELDS_TREND);
		return r;
	}
	
	@GET
	@Path("/field.insert.influence")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInsertFieldTypesInfluence() {
		TypeResponse r = new TypeResponse();
		r.setName("field.insert.influence");
		r.getMembers().addAll(Fields.INSERT_FIELDS_INFLUENCE);
		return r;
	}
	
	@GET
	@Path("/field.insert.usage")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInsertFieldTypesUsage() {
		TypeResponse r = new TypeResponse();
		r.setName("field.insert.usage");
		r.getMembers().addAll(Fields.INSERT_FIELDS_USAGE);
		return r;
	}
	
	@GET
	@Path("/field.source")
	@Produces(MediaType.APPLICATION_JSON)
	public Map<String,String> getFieldSources() {
		Map<String,String> r = Fields.FIELD_SOURCES;
		return r;
	}
}
