<?php
/**
 * Runtime compatibility checks.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Application;

/**
 * Reports supported and recommended runtime versions.
 */
final class Compatibility {
	const MINIMUM_PHP       = '7.4';
	const RECOMMENDED_PHP   = '8.3';
	const MINIMUM_WORDPRESS = '6.4';

	/**
	 * Whether the runtime can activate the plugin.
	 *
	 * @param string $php_version PHP version.
	 * @param string $wp_version  WordPress version.
	 * @return bool
	 */
	public static function is_supported( $php_version, $wp_version ) {
		return version_compare( $php_version, self::MINIMUM_PHP, '>=' )
			&& version_compare( $wp_version, self::MINIMUM_WORDPRESS, '>=' );
	}

	/**
	 * Register the legacy PHP warning when required.
	 *
	 * @return void
	 */
	public static function register_admin_notice() {
		if ( version_compare( PHP_VERSION, self::RECOMMENDED_PHP, '>=' ) ) {
			return;
		}

		add_action(
			'admin_notices',
			static function () {
				echo '<div class="notice notice-warning"><p>';
				echo esc_html__( 'LocalGuard Scanner supports this PHP version for recovery, but PHP 8.3 or newer is strongly recommended for security.', 'localguard-scanner' );
				echo '</p></div>';
			}
		);
	}
}
