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

import java.util.LinkedHashMap;
import java.util.Map;

import cz.muni.fi.lasaris.sbms.data.entities.AddressGroup;
import cz.muni.fi.lasaris.sbms.data.entities.containers.Aggregation;
import cz.muni.fi.lasaris.sbms.data.entities.values.AggregatedValue;

public class AggregationResponse {
	private String error;
	private Map<String, AggregatedValue> results;
	
	public Map<String, AggregatedValue> getResults() {
		return this.results;
	}
	
	public static AggregationResponse getErrorResponse(String error) {
		AggregationResponse r = new AggregationResponse();
		r.setError(error);
		return r;
	}
	
	private AggregationResponse() {
		this.results = null;
	}
	
	public AggregationResponse(Map<String, AggregatedValue> data) {
		this.results = data;
	}
	
	public AggregationResponse(AggregatedValue v) {
		this.results = new LinkedHashMap<String, AggregatedValue>();
		this.results.put("value", v);
	}
	
	public AggregationResponse(Aggregation<AddressGroup> a) {
		this.results = new LinkedHashMap<String, AggregatedValue>();
		a.forEach((k,v) -> this.results.put(k.getName(), v));
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}
}
