<?php

namespace WPProofShield;

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


use WPProofShield\Admin\SettingsPage;
use WPProofShield\Admin\StatsPage;
use WPProofShield\Integration\ApiController;
use WPProofShield\Integration\CommentGuard;
use WPProofShield\Integration\GenericFormGuard;
use WPProofShield\Integration\LoginGuard;
use WPProofShield\Integration\PostedFormGuard;
use WPProofShield\Security\PowVerifier;
use WPProofShield\Security\RateLimiter;
use WPProofShield\Security\ReplayGuard;
use WPProofShield\Security\RequestVerifier;
use WPProofShield\Security\ModeAdvisor;
use WPProofShield\Security\StatsStore;
use WPProofShield\Security\TokenService;
use WPProofShield\Support\AdminMailReporter;
use WPProofShield\Support\PrivacyTools;
use WPProofShield\Support\FeatureAccess\AlwaysEnabledFeatureAccess;
use WPProofShield\Support\FeatureAccess\FeatureAccess;
use WPProofShield\Support\Settings;
final class Plugin {

	public function boot(): void {
		$settings     = new Settings();
		$feature_access = new AlwaysEnabledFeatureAccess();
		$stats        = new StatsStore( $settings );
		$mode_advisor = new ModeAdvisor( $settings, $stats );

		$token_service    = new TokenService( $settings );
		$pow_verifier     = new PowVerifier();
		$replay_guard     = new ReplayGuard();
		$rate_limiter     = new RateLimiter( $settings );
		$request_verifier = new RequestVerifier(
			$settings,
			$mode_advisor,
			$token_service,
			$pow_verifier,
			$replay_guard,
			$rate_limiter,
			$stats
		);

		( new LoginGuard( $settings, $request_verifier, $rate_limiter, $stats ) )->register();
		( new CommentGuard( $settings, $request_verifier, $feature_access ) )->register();
		( new PostedFormGuard( $settings, $request_verifier, $feature_access, $stats ) )->register();
		( new GenericFormGuard( $settings, $feature_access ) )->register();
		( new ApiController( $settings, $mode_advisor, $rate_limiter, $request_verifier, $token_service, $stats, $feature_access ) )->register();
		( new SettingsPage( $settings, $mode_advisor, $feature_access ) )->register();
		( new StatsPage( $stats, $settings, $feature_access ) )->register();
		( new AdminMailReporter( $settings, $stats, $feature_access ) )->register();
		( new PrivacyTools() )->register();
		add_action(
			'wpsh_cleanup_logs',
			static function () use ( $stats ): void {
				$stats->cleanup();
			}
		);
		add_action(
			'wpsh_process_geo_queue',
			static function () use ( $stats ): void {
				$stats->processGeoQueue();
			}
		);
	}
}
