Files
faumaray 7975f2b38e update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-25 23:44:42 +03:00

50 lines
1.6 KiB
C++

#pragma once
#include <ConfigTypes.hpp>
#include <Types.hpp>
#include <filesystem>
#include <string>
#include <string_view>
namespace Echoion::Core
{
// Configuration loader for JSON config files (internal to Core).
//
// Api::AppConfig is serialized directly through Void::Json reflection —
// no mirror DTOs. The on-disk shape follows the domain types: durations
// are strings ("30000ms"), enums are names ("High"), the proxy is a
// nested object (or null), and time_points are duration strings.
class ConfigLoader
{
public:
// Load configuration from JSON file
[[nodiscard]] static Api::Result<Api::AppConfig>
loadFromFile(const std::filesystem::path& path);
// Parse, migrate, and normalize a complete JSON configuration. This
// is shared by file loading and live configuration updates so
// legacy fields have identical behavior through both entry points.
[[nodiscard]] static Api::Result<Api::AppConfig>
loadFromJson(std::string_view json);
// Save configuration to JSON file
[[nodiscard]] static Api::Result<void>
saveToFile(const std::filesystem::path& path,
const Api::AppConfig& config);
// Get default configuration path
[[nodiscard]] static std::filesystem::path getDefaultConfigPath();
// Create default configuration
[[nodiscard]] static Api::AppConfig createDefaultConfig();
// Clamp/normalize values that carry hard limits after loading
// (e.g. the yt-dlp concurrency cap). Applied by all load/update
// paths.
static void normalize(Api::AppConfig& config);
};
} // namespace Echoion::Core