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 smIPadress = "localhost";
	private int smPort = 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("smIPadress");
		
		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("smIPadress", smIPadress);
		ConfigFile.SetProperty("smPort", "" + smPort);
		ConfigFile.SetProperty("smGenerateBinarieFile",""+smGenerateBinarieFile); 
		ConfigFile.SetProperty("smBinarieOutputFile",smBinarieOutputFile); 
		ConfigFile.SetProperty("smBinarieOutputFile",smBinarieOutputDirectory); 
		ConfigFile.SetProperty("smBinarieFilePrefixDate",""+smBinarieFilePrefixDate);
		
	}

	private void initialiseFromProperties()
	{
		smIPadress = ConfigFile.GetProperty("smIPadress");
		smPort = Integer.parseInt(ConfigFile.GetProperty("smPort"));
		smGenerateBinarieFile = Boolean.parseBoolean(ConfigFile.GetProperty("smGenerateBinarieFile")); 
		smBinarieOutputFile =  ConfigFile.GetProperty("smBinarieOutputFile"); 
		smBinarieOutputDirectory =  ConfigFile.GetProperty("smBinarieOutputDirectory"); 
		smBinarieFilePrefixDate =  Boolean.parseBoolean(ConfigFile.GetProperty("smBinarieFilePrefixDate"));
		
		
	}

	public String getSmIPadress() {
		return smIPadress;
	}

	public void setSmIPadress(String iPadress) {
		smIPadress = iPadress;
	}

	public int getSmPort() {
		return smPort;
	}

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

	public String toString() {
		return smIPadress + ":" + smPort;
	}

	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;
	}


}
