package mil.dds.anet.config;

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

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;

import io.dropwizard.Configuration;
import io.dropwizard.db.DataSourceFactory;

public class AnetConfiguration extends Configuration {

	private boolean developmentMode;
	private boolean redirectToHttps = false;

	private SmtpConfiguration smtp;
	private String emailFromAddr;
	private String serverUrl;

	@NotNull
	private Map<String,String> waffleConfig = new HashMap<String,String>();

	@Valid
	@NotNull
	private DataSourceFactory database = new DataSourceFactory();

	@NotNull
	private Map<String, Map<String, String>> views = Collections.emptyMap();

	@JsonProperty("database")
	public void setDataSourceFactory(DataSourceFactory factory) {
		this.database = factory;
    }

	@JsonProperty("database")
	public DataSourceFactory getDataSourceFactory() {
		return database;
    }

	public boolean isDevelopmentMode() {
		return developmentMode;
	}

	public void setDevelopmentMode(boolean developmentMode) {
		this.developmentMode = developmentMode;
	}

	public boolean getRedirectToHttps() {
		return redirectToHttps;
	}

	public void setRedirectToHttps(boolean redirectToHttps) {
		this.redirectToHttps = redirectToHttps;
	}

	@JsonProperty("views")
	public Map<String, Map<String, String>> getViews() {
		return views;
	}

	@JsonProperty("views")
	public void setViews(Map<String, Map<String, String>> views) {
		final ImmutableMap.Builder<String, Map<String, String>> builder = ImmutableMap.builder();
		for (Map.Entry<String, Map<String, String>> entry : views.entrySet()) {
			builder.put(entry.getKey(), ImmutableMap.copyOf(entry.getValue()));
		}
		this.views = builder.build();
	}

	public Map<String, String> getWaffleConfig() {
		return waffleConfig;
	}

	public void setWaffleConfig(Map<String,String> config) {
		this.waffleConfig = config;
	}

	public SmtpConfiguration getSmtp() {
		return smtp;
	}

	public void setSmtp(SmtpConfiguration smtp) {
		this.smtp = smtp;
	}

	public String getEmailFromAddr() {
		return emailFromAddr;
	}

	public void setEmailFromAddr(String emailFromAddr) {
		this.emailFromAddr = emailFromAddr;
	}
	
	public String getServerUrl() {
		return serverUrl;
	}

	public void setServerUrl(String serverUrl) {
		this.serverUrl = serverUrl;
	}

	public static class SmtpConfiguration {
		private String hostname;
		private Integer port = 587;
		private String username;
		private String password;
		private Boolean startTls = true;
		private boolean disabled = false;
		
		public String getHostname() {
			return hostname;
		}
		
		public void setHostname(String hostname) {
			this.hostname = hostname;
		}
		
		public Integer getPort() {
			return port;
		}
		
		public void setPort(Integer port) {
			this.port = port;
		}
		
		public String getUsername() {
			return username;
		}
		
		public void setUsername(String username) {
			this.username = username;
		}
		
		public String getPassword() {
			return password;
		}
		
		public void setPassword(String password) {
			this.password = password;
		}
		
		public Boolean getStartTls() {
			return startTls;
		}
		
		public void setStartTls(Boolean startTls) {
			this.startTls = startTls;
		}

		public boolean isDisabled() {
			return disabled;
		}

		public void setDisabled(boolean disabled) {
			this.disabled = disabled;
		}
	}


}

@@ -586,16 +586,58 @@
 erUrl;%0A%0A
+%09private Map%3CString, Object%3E dictionary;%0A%0A
 %09@NotNul
@@ -2501,32 +2501,200 @@
  serverUrl;%0A%09%7D%0A%0A
+%09public Map%3CString, Object%3E getDictionary() %7B%0A%09%09return dictionary;%0A%09%7D%0A%0A%09public void setDictionary(Map%3CString, Object%3E dictionary) %7B%0A%09%09this.dictionary = dictionary;%0A%09%7D%0A%0A
 %09public static c

Add dictionary to configuration