using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

namespace IWS5.Autotest.IWS5.Helpers
{
	public static class ConfigurationHelper
	{
		private static IConfiguration _configuration;

		public static IConfiguration Configuration => _configuration ??= BuildCustomConfiguration();

		private static IConfiguration BuildCustomConfiguration()
		{
			var builder = new ConfigurationBuilder()
				.Add(new JsonConfigurationSource
				{
					FileProvider = null,
					Path = GetConfigFileName()
				});

			return builder.Build();
		}

		public static string GetAppSetting(string name)
		{
			return Configuration?.GetSection("Configurations")?[name];
		}

		//TODO localdebug
		public static string GetConfigFileName()
		{
//#if LOCALDEBUG
            //return "Configurations.local.json";
//#else
			return "Configurations.json";
//#endif
		}
	}
}