using System.Configuration;

namespace CoreLibrary.Util
{
    public static class Configuration
    {
        /// <summary>
        /// Get boolean configuration key
        /// </summary>
        public static bool GetBooleanConfigKey(string key)
        {
            return ConfigurationManager.AppSettings[key] == "true";
        }

        /// <summary>
        /// Get integer configuration key
        /// </summary>
        public static int GetIntConfigKey(string key)
        {
            string value = ConfigurationManager.AppSettings[key];
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = -1;
                if(int.TryParse(value, out intValue))
                {
                    return intValue;
                }
            }
            return -1;
            
        }

        /// <summary>
        /// Get conection string
        /// </summary>
        public static string GetConnectionString(string key)
        {
            if (ConfigurationManager.ConnectionStrings[key] != null)
            {
                return ConfigurationManager.ConnectionStrings[key].ConnectionString;
            }
            return null;
        }
    }
}
