<?php
/**
 * Get public settings use case.
 *
 * Phase-8 slice 8b Application-layer use case backing the §13.1
 * `GET /affilun/v1/settings/public` REST endpoint documented in
 * `specifications/rest-api-spec.md`. The endpoint returns ONLY
 * the public-safe subset of the §13 settings aggregate: API
 * keys, secrets, encrypted credentials, internal diagnostics,
 * the §13.9 debug-mode flag, the §13.7 sync settings, and the
 * §13.8 cache settings are all excluded by the
 * {@see \Affilun\Presentation\Rest\Mapper\PublicSettingsMapper}
 * that consumes this use case's result.
 *
 * The use case itself is a thin wrapper around
 * {@see SettingsRepository::load()}. It exists for symmetry
 * with the Phase-6 / Phase-7 use cases (so the controller's
 * dependency graph stays uniform) and as the future extension
 * point for caching, default-overlay, and schema-migration
 * concerns that should not pollute the controller.
 *
 * @package Affilun\Application\Settings\UseCase
 */

declare(strict_types=1);

namespace Affilun\Application\Settings\UseCase;

use Affilun\Application\Settings\PluginSettings;
use Affilun\Application\Settings\SettingsRepository;

/**
 * Resolve the §13 plugin-settings snapshot the §13.1 endpoint
 * surfaces (after the public-safe mapper strips secret-bearing
 * fields).
 *
 * See the file-level docblock for the rationale behind keeping
 * this as a thin wrapper rather than inlining the repository
 * call inside the controller.
 */
final class GetPublicSettingsUseCase {

	/**
	 * Backing settings repository.
	 */
	private SettingsRepository $repository;

	/**
	 * Construct the use case with the repository it delegates to.
	 *
	 * @param SettingsRepository $repository Backing settings repository.
	 */
	public function __construct( SettingsRepository $repository ) {
		$this->repository = $repository;
	}

	/**
	 * Load the current §13 settings snapshot.
	 *
	 * Returns {@see PluginSettings::defaults()} when no value has
	 * ever been stored (per the {@see SettingsRepository::load()}
	 * contract).
	 */
	public function execute(): PluginSettings {
		return $this->repository->load();
	}
}
