#pragma once
#include <cstdint>
#include <filesystem>
#include <string>
#include <mw/http_server.hpp>
#include <mw/error.hpp>
#include <mw/url.hpp>
/// Supported authentication email delivery mechanisms.
enum class EmailTransport
{
MAILJET,
FILE
};
/// Validated authentication email configuration.
struct EmailConfig
{
/// Selected delivery mechanism.
EmailTransport transport = EmailTransport::FILE;
/// Sender address used by Mailjet.
std::string from_address;
/// Human-readable sender name used by Mailjet.
std::string from_name;
/// Environment variable containing the Mailjet API key.
std::string mailjet_api_key_environment;
/// Environment variable containing the Mailjet secret key.
std::string mailjet_secret_key_environment;
/// Persistent daily ceiling for attempted Mailjet calls.
std::uint32_t daily_attempt_limit = 180;
/// Private file receiving the latest development link.
std::filesystem::path link_file;
};
/// Validated process configuration.
struct Config
{
/// Normalized absolute HTTP or HTTPS application base URL.
mw::URL base_url;
/// TCP or Unix-domain address on which the server listens.
mw::HTTPServer::ListenAddress listen_address;
/// Root containing application static files.
std::filesystem::path static_root;
/// SQLite database file path.
std::filesystem::path database_path;
/// Private root containing staged and published card assets.
std::filesystem::path card_storage_root;
/// ImageMagick quality used when converting PNG inputs to AVIF.
int avif_quality;
/// Long-side pixel count used for generated thumbnails.
std::uint32_t thumbnail_long_side;
/// Validated administrator email spelling.
std::string administrator_email = "admin@example.com";
/// Normalized immutable administrator identity key.
std::string administrator_email_key = "admin@example.com";
/// Maximum lazily accumulated pulls; lowering it can discard accrual.
std::uint32_t maximum_accumulated_pulls = 3;
/// Authentication email delivery configuration.
EmailConfig email;
};
/// Load, validate, and normalize one TOML process configuration.
mw::E<Config> loadConfig(const std::filesystem::path& config_path);