<?php
/**
 * Uploads Vault Module.
 *
 * Module 5 — protects form-generated upload subdirectories with
 * .htaccess + index.php files that 403 (or redirect) non-admins.
 *
 * Strategy:
 *   - On `wp_handle_upload`, detect uploads landing in a configured "protected"
 *     subdirectory (e.g. forms/, contact-forms/, gravity_forms/, wpforms/).
 *   - Drop a .htaccess and index.php in that subdirectory if not already there.
 *   - On every front-end request to a protected file, gate access via a
 *     PHP fallback (in case .htaccess is ignored, e.g. on nginx).
 *
 * @package Platform\Helm\Modules\UploadsVault
 */

declare( strict_types = 1 );

namespace Platform\Helm\Modules\UploadsVault;

use Platform\Helm\Contracts\ModuleInterface;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class UploadsVaultModule implements ModuleInterface {

	private DirectoryProtector $protector;

	public function __construct() {
		$this->protector = new DirectoryProtector();
	}

	public function id(): string {
		return 'uploads_vault';
	}

	public function name(): string {
		return __( 'Uploads Vault', 'platform-helm' );
	}

	public function description(): string {
		return __( 'Protects form-generated upload subdirectories with .htaccess + index.php. Non-admin direct access is denied.', 'platform-helm' );
	}

	public function default_enabled(): bool {
		return false; // Disk-write; opt-in.
	}

	public function boot(): void {
		$this->protector->register_hooks();
	}
}
