package it.enea.cruise.data;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Getter;
import lombok.extern.log4j.Log4j2;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
@Log4j2
public class InputParameters {

	 @JsonInclude(JsonInclude.Include.NON_NULL)
	private Integer communityid;
	 @JsonInclude(JsonInclude.Include.NON_NULL)
	private Integer queryid;
	 @JsonInclude(JsonInclude.Include.NON_NULL)
	private Integer flowid;
		
	@JsonIgnore
	private String token;
		
	@JsonIgnore
	private String language;
	
	@JsonIgnore
	private Integer userid;
		
	@JsonIgnore
	private HashMap<String, String> parameters = new HashMap<String, String>(); 
	
	
	@Override
	public String toString() {
		String toString = "{";
		for (String key : parameters.keySet()) {
			toString = toString + "\n\t" + key + ":" + parameters.get(key) +",";
		}
		
		return toString.substring(0, toString.length()-1) + "\n}";
	}
	

	public void setToken(String token) {
		this.parameters.put("token", token);
		this.token = token;
	}
	
	public void setCommunityid(Integer communityid) {
		if (communityid != null) {
		this.parameters.put("communityid", communityid.toString());
		this.communityid = communityid;
		}
	}
	
	public void setCommunityid(String communityid) {
		if (communityid != null) {
		this.parameters.put("communityid", communityid);
		this.communityid = new Integer(communityid);
		}
		}
	
	public void setQueryid(Integer queryid) {
		if (queryid != null) {
		this.parameters.put("queryid", queryid.toString());
		this.queryid = queryid;
		}
	}

	public void setParameters(Map<String, Object> otherParameters) {
		for (String key : otherParameters.keySet()) { 
			log.info(key, otherParameters.get(key));
			if(otherParameters.get(key) != null ) {
				this.parameters.put(key.trim(), otherParameters.get(key).toString());
				}
			}
		
	}
	public void setFlowid(Integer flowid) {
		if (flowid != null) {
		this.parameters.put("flowid", flowid.toString());
		this.flowid = flowid;
		}
	}

	public void setLanguage(String language) {
		this.parameters.put("language", language);
		this.language = language;
	}

	public void setUserid(Integer userid) {
		this.parameters.put("userid", userid.toString());
		this.userid = userid;
	}
	
}
