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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlRootElement;

import cz.muni.fi.lasaris.sbms.api.entities.DataPoint;
import cz.muni.fi.lasaris.sbms.model.Fields;

@XmlRootElement
public class DataPointsRequest {
	private static Map<String, String> sparqlVars;
	
	public static String getSPARQLvar(String field) {
		if(sparqlVars == null) {
			sparqlVars = new HashMap<String,String>();
			for(String f : Fields.FILTER_FIELDS) {
				sparqlVars.put(f, f.replace(".", ""));
			}
		}
		return sparqlVars.get(field);
	}
	
	
	private DataPoint dataPoint;
	private List<String> responseFields;
	private String grouping;
	
	private String[] g;
	
	public List<String> getResponseFields() {
		return responseFields;
	}

	public DataPointsRequest() {
		
		responseFields = new ArrayList<String>();
	}
	
	public DataPoint getDataPoint() {
		return dataPoint;
	}
	
	public void setDataPoint(DataPoint dp) {
		this.dataPoint = dp;
	}
	
	public String getGrouping() {
		return grouping;
	}
	
	public String getGrouping(int i) {
		if(g == null || i < 0 || i > 2) {
			return Fields.DEFAULT_GROUPING;
		}
		return g[i];
	}

	public void setGrouping(String grouping) {
		this.grouping = grouping;
		if(grouping != null) {
			String[] gs = grouping.split("\\.");
			this.g =(gs.length > 1) ? new String[] {gs[0], Character.toUpperCase(gs[1].charAt(0)) + gs[1].substring(1)}
			: new String[] {gs[0], gs[0]};
		} else {
			this.g = new String[] { Fields.DEFAULT_GROUPING, Fields.DEFAULT_GROUPING };
		}
	}
	
}
