package org.josast.app.amicalsat.cli;

import java.util.logging.Logger;

import org.josast.property.CONFIG;
import org.josast.property.ConfigObject;

public class AmicalsatCliConf extends ConfigObject {

	
	private Logger log = Logger.getLogger(getClass().getName());
	
	private String configurationFile = "defaultConfigFile.ini";
	private String binarieFile=null;
	private String textualFile = null;
	private String configFileDefined  = "true";
	private String IPadress = "localhost";
	private int port = 8100;

	protected CONFIG ConfigFile = CONFIG.getInstance();
	
	
	public AmicalsatCliConf() {
		 
		initialise(configurationFile);
		
	}
	public AmicalsatCliConf(String configFilename) {
		configurationFile = configFilename;
		initialise(configurationFile);

	}
	
	private void  initialise(String configFilename )
	{
		// vérifie si la propriété est dans le fichier
		ConfigFile.setFileName(configurationFile);
		String  temp = ConfigFile.GetProperty("configFileDefined");
		
		if (temp == null) {
			// config file not initialised

			log.severe("properties file not initialised - a file is created with properties with defaults value");
			System.out.println("config file does not content required properties \n the file " + configFilename
					+ " has been set up with default properties to configure");
			Save();

		} else {
			IPadress = temp;
			String portString = ConfigFile.GetProperty("port");
			port = Integer.parseInt(portString);
		}
	}
	
	public void Save()
	{
		ConfigFile.SetProperty("configFileDefined", configFileDefined);
		ConfigFile.SetProperty("port", "" + port);
		ConfigFile.SetProperty("IPadress", "" + IPadress);
		ConfigFile.SetProperty("binarieFile", "" + binarieFile);
		ConfigFile.SetProperty("textualFile", "" + textualFile);
		ConfigFile.SetProperty("configurationFile", "" + configurationFile);
 
		
	}	
	
	public String getConfigurationFile() {
		return configurationFile;
	}
	public void setConfigurationFile(String configurationFile) {
		this.configurationFile = configurationFile;
	}
	public String getBinarieFile() {
		return binarieFile;
	}
	public void setBinarieFile(String binariefile) {
		this.binarieFile = binariefile;
	}
	public String getTextualFile() {
		return textualFile;
	}
	public void setTextualFile(String textualFile) {
		this.textualFile = textualFile;
	}
	
	
	
	
	

}
