package com.uservoice.uservoicesdk;

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

public class Config {
	private String site;
	private String key;
	private String secret;
	private String ssoToken;
	private String email;
	private String name;
	private String guid;
	private Map<String, String> customFields;
	private int topicId = -1;
	private int forumId = -1;
	private boolean showForum = true;
	private boolean showPostIdea = true;
	private boolean showContactUs = true;
	private boolean showKnowledgeBase = true;
	private Map<String,Object> userTraits = new HashMap<String,Object>();
	
	public Config(String site, String key, String secret) {
		this.site = site;
		this.key = key;
		this.secret = secret;
	}
	
	public Config(String site, String key, String secret, String ssoToken) {
		this(site, key, secret);
		this.ssoToken = ssoToken;
	}
	
	public Config(String site, String key, String secret, String email, String name, String guid) {
		this(site, key, secret);
		this.email = email;
		this.name = name;
		this.guid = guid;
	}
	
	public String getSite() {
		return site;
	}
	
	public String getKey() {
		return key;
	}
	
	public String getSecret() {
		return secret;
	}
	
	public String getSsoToken() {
		return ssoToken;
	}
	
	public String getEmail() {
		return email;
	}
	
	public String getName() {
		return name;
	}

	public String getGuid() {
		return guid;
	}

	public Map<String, String> getCustomFields() {
		return customFields;
	}

	public void setCustomFields(Map<String, String> customFields) {
		this.customFields = customFields;
	}

	public int getTopicId() {
		return topicId;
	}

	public void setTopicId(int topicId) {
		this.topicId = topicId;
	}

	public int getForumId() {
		if (forumId == -1)
			return Session.getInstance().getClientConfig().getDefaultForumId();
		return forumId;
	}

	public void setForumId(int forumId) {
		this.forumId = forumId;
	}

	public boolean shouldShowForum() {
		if (Session.getInstance().getClientConfig() != null && !Session.getInstance().getClientConfig().isFeedbackEnabled())
			return false;
		return showForum;
	}

	public void setShowForum(boolean showForum) {
		this.showForum = showForum;
	}

	public boolean shouldShowPostIdea() {
		if (Session.getInstance().getClientConfig() != null && !Session.getInstance().getClientConfig().isFeedbackEnabled())
			return false;
		return showPostIdea;
	}

	public void setShowPostIdea(boolean showPostIdea) {
		this.showPostIdea = showPostIdea;
	}

	public boolean shouldShowContactUs() {
		if (Session.getInstance().getClientConfig() != null && !Session.getInstance().getClientConfig().isTicketSystemEnabled())
			return false;
		return showContactUs;
	}

	public void setShowContactUs(boolean showContactUs) {
		this.showContactUs = showContactUs;
	}

	public boolean shouldShowKnowledgeBase() {
		if (Session.getInstance().getClientConfig() != null && !Session.getInstance().getClientConfig().isTicketSystemEnabled())
			return false;
		return showKnowledgeBase;
	}

	public void setShowKnowledgeBase(boolean showKnowledgeBase) {
		this.showKnowledgeBase = showKnowledgeBase;
	}
	
	public void putUserTrait(String key, String value) {
		userTraits.put(key, value);
	}
	
	public void putUserTrait(String key, int value) {
		userTraits.put(key, value);
	}
	
	public void putUserTrait(String key, boolean value) {
		userTraits.put(key, value);
	}
	
	public void putUserTrait(String key, float value) {
		userTraits.put(key, value);
	}
	
	public void putUserTrait(String key, Date value) {
		userTraits.put(key, value.getTime() / 1000);
	}
	
	public void putAccountTrait(String key, String value) {
		putUserTrait("account_" + key, value);
	}
	
	public void putAccountTrait(String key, int value) {
		putUserTrait("account_" + key, value);
	}
	
	public void putAccountTrait(String key, boolean value) {
		putUserTrait("account_" + key, value);
	}
	
	public void putAccountTrait(String key, float value) {
		putUserTrait("account_" + key, value);
	}

	public void putAccountTrait(String key, Date value) {
		putUserTrait("account_" + key, value);
	}
	
	public Map<String, Object> getUserTraits() {
		return userTraits;
	}
}

@@ -737,333 +737,8 @@
 %7D%0A%09%0A
-%09public Config(String site, String key, String secret, String ssoToken) %7B%0A%09%09this(site, key, secret);%0A%09%09this.ssoToken = ssoToken;%0A%09%7D%0A%09%0A%09public Config(String site, String key, String secret, String email, String name, String guid) %7B%0A%09%09this(site, key, secret);%0A%09%09this.email = email;%0A%09%09this.name = name;%0A%09%09this.guid = guid;%0A%09%7D%0A%09%0A
 %09pub
@@ -2779,32 +2779,246 @@
 ledgeBase;%0A%09%7D%0A%09%0A
+%09public void identifyUser(String id, String name, String email) %7B%0A%09%09guid = id;%0A%09%09this.name = name;%0A%09%09this.email = email;%0A%09%09putUserTrait(%22id%22, id);%0A%09%09putUserTrait(%22name%22, name);%0A%09%09putUserTrait(%22email%22, email);%0A%09%7D%0A%09%0A
 %09public void put

Remove sso and add identifyUser