/*******************************************************************************
 *  Copyright 2017 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.hl7282.utils;

import java.io.File;


/**
 * This class sets the Configuration of HL7 Library.
 */
public class HL7Config 
{
	private static HL7Config objHL7Config = null;

	/**
	 * The enum log mode.
	 */
	private EnumLogMode enumLogMode = EnumLogMode.LOGGING_DISSABLED;

	/**
	 * The enum locale.
	 */
	private EnumLocale enumLocale = EnumLocale.US;

	
	/**
	 * This Contructor initializes the Properties as specified in HL7Config
	 */
	private HL7Config()
	{
	}

	/**
	 * This Contructor initializes the Properties as provided by the user.
	 * The function accepts enum EnumLogMode and EnumLocale.
	 * EnumLogMode specifies the log mode status and EnumLocale specifies the locale settings.
	 * @param enumLogMode Enum specifying whether log mode is ON or OFF.
	 */
	private HL7Config(EnumLogMode enumLogMode, EnumLocale enumLocale)
	{
		this();
		this.enumLogMode = enumLogMode;
		this.enumLocale = enumLocale;
	}

	/**
	 * Constructs instance of HL7Config
	 * @return instance of HL7Config class
	 */
	public static HL7Config createInstance() 
	{
		if(objHL7Config == null)
			objHL7Config = new HL7Config();
		return objHL7Config;
	}

	/**
	 * Constructs instance of HL7Config for specified logmode and locale
	 * @param enumLogMode enum represents logging mode
	 * @param enumLocale enum specify locale specific information.
	 * @return HL7Config - instance of HL7Config class for specified logmode and locale
	 */
	public static HL7Config createInstance(EnumLogMode enumLogMode, EnumLocale enumLocale)
	{
		if(objHL7Config == null)
			objHL7Config = new HL7Config(enumLogMode, enumLocale);
		return objHL7Config;
	}

	/**
	 * Retrieves whether logging mode is on.
	 * @return isLoggerDebugOn - boolean value indicating whether debug mode is.
	 */
	public boolean isLoggingOn()
	{
		if(enumLogMode.equals(EnumLogMode.LOGGING_ENABLED))
			return true;
		else
			return false;
	}

	/**
	 * Sets logging mode as ON. If the user enables logging then data is logged into log file.
	 */
	public void enableLogging()
	{
		enumLogMode = EnumLogMode.LOGGING_ENABLED;
	}

	/**
	 * Sets logging mode as ON. If the user enables logging then data is logged into log file.
	 * @param strLogLocation Path of file in which logging is done. 
	 */
	public void enableLogging(String strLogLocation)
	{
		this.enumLogMode = EnumLogMode.LOGGING_ENABLED;
		if(strLogLocation == null || strLogLocation=="")
			strLogLocation = StandardMethods.getTempDirectoryStorage() + "CDAC-SDK/HL7-J/Logs";
		File logDir = new File(strLogLocation);
		logDir.mkdirs();
		String tempFileName = logDir.getPath() + File.separator + StandardMethods.generateUUID() + ".log";
		HL7Logger.getLogger(tempFileName);
	}


	/**
	 * Sets logging mode as OFF. If the user dissables logging mode then data is not logged into log file.
	 */
	public void disableLogging()
	{
		enumLogMode = EnumLogMode.LOGGING_DISSABLED;
	}

	/**
	 * Retrieves Locale property
	 * @return String - Locale used in string
	 */
	public String getLocale()
	{
		return this.enumLocale.getValue();
	}

	/**
	 * Sets Locale Property
	 * @param enumLocale specifies locale specific information.
	 */
	public void  setLocale(EnumLocale enumLocale)
	{
		this.enumLocale = enumLocale;
	}
	
}