package org.josast.ModuleSoundModem;

import java.util.logging.Logger;

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

/**
 * @author Christophe
 *
 */
public class SoundModemConfiguration extends ConfigObject {

	private Logger log = Logger.getLogger(getClass().getName());

	private String IPadress = "localhost";
	private int port = 8100;
	private boolean smGenerateBinarieFile = false;
	private String smBinarieOutputFile = "soundmodem.bin";
	private String smBinarieOutputDirectory = "SoundModemOuput";

	private boolean smBinarieFilePrefixDate = false;
	
	
	protected CONFIG ConfigFile = CONFIG.getInstance();

	public SoundModemConfiguration(String configFilename) {
		super(configFilename);
		// vérifie si la propriété est dans le fichier
		String temp = ConfigFile.GetProperty("IPadress");
		
		if (temp == null) {
			// config file not initialised
			initialisePropertiesFile();
			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 properties to configure");

		} else {
			initialiseFromProperties();
		}

	}
	
	private void initialisePropertiesFile() {
		ConfigFile.SetProperty("IPadress", IPadress);
		ConfigFile.SetProperty("port", "" + port);
		ConfigFile.SetProperty("smGenerateBinarieFile",""+smGenerateBinarieFile); 
		ConfigFile.SetProperty("smBinarieOutputFile",smBinarieOutputFile); 
		ConfigFile.SetProperty("smBinarieOutputFile",smBinarieOutputDirectory); 
		ConfigFile.SetProperty("smBinarieFilePrefixDate",""+smBinarieFilePrefixDate);
		
	}

	private void initialiseFromProperties()
	{
		IPadress = ConfigFile.GetProperty("IPadress");
		String portString = ConfigFile.GetProperty("port");
		port = Integer.parseInt(portString);
		smGenerateBinarieFile = Boolean.getBoolean(ConfigFile.GetProperty("smGenerateBinarieFile")); 
		smBinarieOutputFile =  ConfigFile.GetProperty("smBinarieOutputFile"); 
		smBinarieOutputDirectory =  ConfigFile.GetProperty("smBinarieOutputDirectory"); 
		smBinarieFilePrefixDate =  Boolean.getBoolean(ConfigFile.GetProperty("smBinarieFilePrefixDate"));
		
		
		
		
	}

	public String getIPadress() {
		return IPadress;
	}

	public void setIPadress(String iPadress) {
		IPadress = iPadress;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String toString() {
		return IPadress + ":" + port;
	}

	public boolean isSmGenerateBinarieFile() {
		return smGenerateBinarieFile;
	}

	public void setSmGenerateBinarieFile(boolean smGenerateBinarieFile) {
		this.smGenerateBinarieFile = smGenerateBinarieFile;
	}

	public String getSmBinarieOutputFile() {
		return smBinarieOutputFile;
	}

	public void setSmBinarieOutputFile(String smBinarieOutputFile) {
		this.smBinarieOutputFile = smBinarieOutputFile;
	}

	public boolean isSmBinarieFilePrefixDate() {
		return smBinarieFilePrefixDate;
	}

	public void setSmBinarieFilePrefixDate(boolean smBinarieFilePrefixDate) {
		this.smBinarieFilePrefixDate = smBinarieFilePrefixDate;
	}
	
	public String getSmBinarieOutputDirectory() {
		return smBinarieOutputDirectory;
	}

	public void setSmBinarieOutputDirectory(String smBinarieOutputDirectory) {
		this.smBinarieOutputDirectory = smBinarieOutputDirectory;
	}


}
