<?php
/**
 * Module Service Provider
 *
 * Registers all plugin modules using the ModuleRegistry for dependency-aware
 * initialization. All modules now extend AbstractModule and use the registry.
 *
 * @package     WPUltimateSecurity\UltimateSecurity\Bootstrap\Providers
 * @since       2.0.0
 */

declare(strict_types=1);

namespace WPUltimateSecurity\UltimateSecurity\Bootstrap\Providers;

use WPUltimateSecurity\UltimateSecurity\Contracts\ServiceProviderInterface;
use WPUltimateSecurity\UltimateSecurity\Modules\Authentication\ActiveLogins;
use WPUltimateSecurity\UltimateSecurity\Modules\Authentication\Authentication2FA;
use WPUltimateSecurity\UltimateSecurity\Modules\Authentication\LoginControl;
use WPUltimateSecurity\UltimateSecurity\Modules\Authentication\LoginLimit;
use WPUltimateSecurity\UltimateSecurity\Modules\Authentication\LoginNotifications;
use WPUltimateSecurity\UltimateSecurity\Modules\Authentication\PasswordPolicies;
use WPUltimateSecurity\UltimateSecurity\Modules\Compatibility\CompatibilityManager;
// Removed: SecurityHeaders - server-level feature (see SERVER_LEVEL_FEATURES.md)
use WPUltimateSecurity\UltimateSecurity\Modules\Maintenance\DeactivationUrl;
use WPUltimateSecurity\UltimateSecurity\Modules\Maintenance\ImportExport;
use WPUltimateSecurity\UltimateSecurity\Modules\Maintenance\MoreTools;
use WPUltimateSecurity\UltimateSecurity\Modules\Maintenance\SaltChange;
use WPUltimateSecurity\UltimateSecurity\Modules\Maintenance\SimpleCleanup;
use WPUltimateSecurity\UltimateSecurity\Modules\Maintenance\UpdateManager;
use WPUltimateSecurity\UltimateSecurity\Modules\Monitoring\BasicSecurityScore;
use WPUltimateSecurity\UltimateSecurity\Modules\Monitoring\Dashboard\DashboardWidget;
use WPUltimateSecurity\UltimateSecurity\Modules\Monitoring\SimpleEventLogger;
use WPUltimateSecurity\UltimateSecurity\Modules\Monitoring\SiteHealth\SiteHealthInfo;
use WPUltimateSecurity\UltimateSecurity\Modules\Monitoring\VulnerabilityScanner\VulnerabilityScanner;
use WPUltimateSecurity\UltimateSecurity\Modules\Protection\CloudflareTurnstile;
use WPUltimateSecurity\UltimateSecurity\Modules\Protection\ContentProtection;
use WPUltimateSecurity\UltimateSecurity\Modules\Protection\GoogleRecaptcha;
// Removed: IpRestrictions - server-level feature (see SERVER_LEVEL_FEATURES.md)
// Removed: UrlGuard - server logs do this better (see SERVER_LEVEL_FEATURES.md)
use WPUltimateSecurity\UltimateSecurity\Modules\Setup\SecurityWizard;
use WPUltimateSecurity\UltimateSecurity\Modules\TestMode\TestModeModule;
use WPUltimateSecurity\UltimateSecurity\Services\ModuleRegistry;

/**
 * Registers and initializes all plugin modules.
 *
 * All modules extend AbstractModule and are registered with the ModuleRegistry
 * for dependency-aware initialization and introspection support.
 *
 * @since 2.0.0
 */
class ModuleServiceProvider implements ServiceProviderInterface
{
    /**
     * All modules that extend AbstractModule.
     *
     * @var string[]
     */
    private const MODULES = [
        // Monitoring (SimpleEventLogger first for logging dependencies)
        SimpleEventLogger::class,
        BasicSecurityScore::class,
        DashboardWidget::class,
        SiteHealthInfo::class,
        VulnerabilityScanner::class,

        // Authentication
        ActiveLogins::class,
        Authentication2FA::class,
        LoginControl::class,
        LoginLimit::class,
        LoginNotifications::class,
        PasswordPolicies::class,

        // Protection
        CloudflareTurnstile::class,
        GoogleRecaptcha::class,
        ContentProtection::class,
        // Removed: IpRestrictions::class - server-level feature
        // Removed: UrlGuard::class - server logs do this better

        // Hardening
        // Removed: SecurityHeaders::class - server-level feature

        // Maintenance
        DeactivationUrl::class,
        ImportExport::class,
        MoreTools::class,
        SaltChange::class,
        SimpleCleanup::class,
        UpdateManager::class,

        // System
        CompatibilityManager::class,
        SecurityWizard::class,
        TestModeModule::class,
    ];

    /**
     * Register all modules.
     *
     * @return void
     */
    public function register(): void
    {
        // Register all modules with the ModuleRegistry
        foreach (self::MODULES as $moduleClass) {
            ModuleRegistry::register($moduleClass);
        }

        // Initialize modules (sorted by dependencies)
        ModuleRegistry::init();

        // Boot all enabled modules
        ModuleRegistry::bootAll();

        // Fire action for Pro and other extensions
        do_action('ultimate_security_modules_registered', ModuleRegistry::getAllMetadata());
    }
}
