using Microsoft.Extensions.Configuration;

namespace e_suite.Service.Mail.Helper;

public static class ConfigurationHelper
{
    public static T? GetConfigValue<T>( this IConfiguration configuration, string environmentVariable, string key, T defaultValue )
    {
        var envVariable = Environment.GetEnvironmentVariable(environmentVariable);
        
        if (!string.IsNullOrWhiteSpace(envVariable) )
            return (T?)Convert.ChangeType(envVariable, typeof(T));

        return configuration.GetValue(key, defaultValue);
    }
}