<?php
/**
 * Plugin activation.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Application\Lifecycle;

use LocalGuardScanner\Application\Compatibility;
use LocalGuardScanner\Infrastructure\Database\Migrator;
use LocalGuardScanner\Infrastructure\WordPress\Capabilities;
use LocalGuardScanner\Infrastructure\WordPress\CronScheduler;

/**
 * Performs idempotent activation work.
 */
final class Activator {
	/**
	 * Activate the plugin.
	 *
	 * @param bool $network_wide Whether network activation was requested.
	 * @return void
	 */
	public static function activate( $network_wide = false ) {
		global $wp_version;

		if ( ! Compatibility::is_supported( PHP_VERSION, (string) $wp_version ) ) {
			deactivate_plugins( plugin_basename( LOCALGUARD_SCANNER_FILE ) );
			wp_die( esc_html__( 'LocalGuard Scanner requires WordPress 6.4 or newer and PHP 7.4 or newer.', 'localguard-scanner' ) );
		}

		Migrator::migrate();
		Capabilities::install( (bool) $network_wide );
		CronScheduler::schedule_daily();
		CronScheduler::schedule_cleanup();
	}
}
