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);
		}
	}
	
	// TODO getAddressTypes
	
	@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")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInsertFieldTypes() {
		TypeResponse r = new TypeResponse();
		r.setName("field.insert");
		r.getMembers().addAll(Fields.INSERT_FIELDS);
		return r;
	}
	
	@GET
	@Path("/field.source")
	@Produces(MediaType.APPLICATION_JSON)
	public Map<String,String> getFieldSources() {
		Map<String,String> r = Fields.FIELD_SOURCES;
		return r;
	}
}
