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

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();
	}
	
	// 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("/property.domain")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getPropDomainTypes() {
		return TypesProvider.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("/grouping")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getGroupingTypes() {
		TypeResponse r = new TypeResponse();
		r.setName("grouping");
		r.getMembers().addAll(Fields.GROUPINGS);
		return r;
	}
	
	@GET
	@Path("/filterField")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getFilterFieldTypes() {
		TypeResponse r = new TypeResponse();
		r.setName("filterField");
		r.getMembers().addAll(Fields.FILTER_FIELDS);
		return r;
	}
	
	@GET
	@Path("/dataField")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getDataFieldTypes() {
		TypeResponse r = new TypeResponse();
		r.setName("infoField");
		r.getMembers().addAll(Fields.DATA_FIELDS);
		return r;
	}
	
	@GET
	@Path("/insertField")
	@Produces(MediaType.APPLICATION_JSON)
	public TypeResponse getInsertFieldTypes() {
		TypeResponse r = new TypeResponse();
		r.setName("insertField");
		r.getMembers().addAll(Fields.INSERT_FIELDS);
		return r;
	}
}
