/**
 * 
 */
package org.josast.EntrysatDecoder;

import org.josast.property.CONFIG;

/**
 * Singleton to manage all application parameter 
 * The default configuration is automaticaly saved in a properties file.
 * @author christophe
 * 
 * 
 */
public class Configuration {
	
	
	/*
	 * parameter with default value
	 */
	private String callsign="Anonymous";
	private String longitude="0.0W";
	private String latitude="0.0N";
	
	private String soundModemIP="127.0.0.1";
	private String soundModemPort="8100";
	
	private String SIDSEntrySatSource="Anonymous";
	private String SIDSEntryUrl="https://amsat.electrolab.fr/SIDS";
	private String SIDSSatnogsSource="Anonymous";
	private String SIDSSatnogsURL="https://db.satnogs.org/api/telemetry/";
	private String SIDSSatnogs="0";
	private String SIDSEntrySat="1";
	private int Norad=99990; // default value - equivalent to satnogs
	private boolean SISD_SatNogs = false;
	private boolean SIDS_EntrySat = true;

	
	private CONFIG conf = CONFIG.getInstance();
	
    public static Configuration getInstance()
    {
        return SingletonHolder.instance;
    }
    
    public boolean isSISD_SatNogs() {
  
		return SISD_SatNogs;
	}

	public boolean isSIDS_EntrySat() {
		return SIDS_EntrySat;
	}

	private Configuration()
    {
    	if ( conf.GetProperty("Callsign")!=null)
		{
    		 callsign = conf.GetProperty("Callsign");
    		 latitude = conf.GetProperty("Latitude");
    		 longitude = conf.GetProperty("Longitude");
			
    		 SIDSEntrySatSource=conf.GetProperty("SIDSEntrySatSource");
    		 SIDSEntryUrl=conf.GetProperty("SIDSEntryUrl");
    		 SIDSSatnogsSource=conf.GetProperty("SIDSSatnogsSource");
    		 SIDSSatnogsURL=conf.GetProperty("SIDSSatnogsURL");
    		 SIDSSatnogs=conf.GetProperty("SIDSSatnogs");
    		 SIDSEntrySat=conf.GetProperty("SIDSEntrySat");
    		 soundModemIP =  conf.GetProperty("soundModemIP");
    		 soundModemPort =  conf.GetProperty("soundModemPort");
    		 Norad = Integer.parseUnsignedInt(conf.GetProperty("NoradID").trim());
    		 if (SIDSSatnogs.contentEquals("1") )
    		 {
    			 SISD_SatNogs=true;
    		 } else
    		 {
    			 SISD_SatNogs=false;
    		 }
    		 if (SIDSEntrySat.contentEquals("1") )
    		 {
    			 SIDS_EntrySat=true;
    		 } else
    		 {
    			 SIDS_EntrySat=false;
    		 }
		
		}
    	else // si le fichier n'existe pas, il est créé par défaut
    	{
    		 save();
    	}
		
    
    	
    }
     
   
    private static class SingletonHolder
    {       
       
        private final static Configuration instance = new Configuration();
    }
 


	public String getCallsign() {
		return callsign;
	}

	public void setCallsign(String callsign) {
		this.callsign = callsign;
	}

	public String getLongitude() {
		return longitude;
	}

	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	public String getLatitude() {
		return latitude;
	}

	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}

	public String getSIDSEntrySatSource() {
		return SIDSEntrySatSource;
	}

	public void setSIDSEntrySatSource(String sIDSEntrySatSource) {
		SIDSEntrySatSource = sIDSEntrySatSource;
	}

	public String getSIDSEntryUrl() {
		return SIDSEntryUrl;
	}

	public void setSIDSEntryUrl(String sIDSEntryUrl) {
		SIDSEntryUrl = sIDSEntryUrl;
	}

	public String getSIDSSatnogsSource() {
		return SIDSSatnogsSource;
	}

	public void setSIDSSatnogsSource(String sIDSSatnogsSource) {
		SIDSSatnogsSource = sIDSSatnogsSource;
	}

	public String getSIDSSatnogsURL() {
		return SIDSSatnogsURL;
	}

	public void setSIDSSatnogsURL(String sIDSSatnogsURL) {
		SIDSSatnogsURL = sIDSSatnogsURL;
	}

	public String getSIDSSatnogs() {
		return SIDSSatnogs;
	}

	public void setSIDSSatnogs(String sIDSSatnogs) {
		SIDSSatnogs = sIDSSatnogs;
		 if (SIDSSatnogs.contentEquals("1") )
		 {
			 SISD_SatNogs=true;
		 } else
		 {
			 SISD_SatNogs=false;
		 }
	}

	public String getSIDSEntrySat() {
		return SIDSEntrySat;
	}

	public void setSIDSEntrySat(String sIDSEntrySat) {
		SIDSEntrySat = sIDSEntrySat;
		 if (SIDSEntrySat.contentEquals("1") )
		 {
			 SIDS_EntrySat=true;
		 } else
		 {
			 SIDS_EntrySat=false;
		 }
	}

	public String getSoundModemIP() {
		return soundModemIP;
	}

	public void setSoundModemIP(String soundModemIP) {
		this.soundModemIP = soundModemIP;
	}

	public String getSoundModemPort() {
		return soundModemPort;
	}

	public void setSoundModemPort(String soundModemPort) {
		this.soundModemPort = soundModemPort;
	}

	public void save() {
		
		conf.SetProperty("Callsign",callsign);
		conf.SetProperty("Latitude",latitude);
		conf.SetProperty("Longitude",longitude);
		
		conf.SetProperty("SIDSEntrySatSource",this.SIDSEntrySatSource);
		conf.SetProperty("SIDSEntryUrl",this.SIDSEntryUrl);
		conf.SetProperty("SIDSSatnogsSource",this.SIDSSatnogsSource);
		conf.SetProperty("SIDSSatnogsURL",this.SIDSSatnogsURL);
		conf.SetProperty("SIDSSatnogs",this.SIDSSatnogs);
		conf.SetProperty("SIDSEntrySat",this.SIDSEntrySat);
		conf.SetProperty("soundModemPort",this.soundModemPort);
		conf.SetProperty("soundModemIP",this.soundModemIP);
		conf.SetProperty("NoradID",""+this.Norad);
	}

	public int getNorad() {
 
		return Norad;
	}

	public void setNorad(int norad) {
		 
		 Norad=norad;
	}

}
