using Microsoft.Extensions.Configuration;
namespace FsToolbox.Cli.Helper
{
///
/// Represents the root configuration settings for the application, including API and credentials.
///
public class AppSettings
{
#region Public Properties
///
/// Gets the API-related settings.
///
public ApiSettings Api { get; init; } = new();
///
/// Gets the credentials settings for authentication.
///
public CredentialsSettings Credentials { get; init; } = new();
#endregion
}
///
/// Contains settings related to the API endpoints.
///
public class ApiSettings
{
#region Public Properties
///
/// Gets the base URL for the API, without the /api path segment.
///
public string BaseUrl { get; init; } = "https://beta.foodsharing.de";
#endregion
}
///
/// Contains credentials and authentication settings.
///
public class CredentialsSettings
{
#region Public Properties
///
/// Gets the email address used for login.
///
public string Email { get; init; } = string.Empty;
///
/// Gets the password used for login.
///
public string Password { get; init; } = string.Empty;
///
/// Gets a value indicating whether two-factor authentication is enabled.
///
public bool TwoFactorEnabled { get; init; }
#endregion
}
///
/// Provides access to the current application settings loaded from configuration.
///
public static class SettingsProvider
{
#region Constants
private static AppSettings? _current;
#endregion
#region Public Properties
///
/// Gets the current application settings instance.
///
public static AppSettings Current => _current ??= Load();
#endregion
#region Private Method Load
private static AppSettings Load()
{
var configuration = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", false, true)
.Build();
var settings = new AppSettings();
configuration.Bind(settings);
return settings;
}
#endregion
}
}