<?php
/**
 * Neutralize stale removable callbacks after an optional runtime is removed.
 *
 * @package VoidPulse
 */

namespace VoidPulse\Core;

defined( 'ABSPATH' ) || exit;

final class DowngradeSafety {
	/**
	 * Clear registered optional schedules once when optional runtime is inactive.
	 *
	 * @param bool $optional_runtime_active Whether an optional runtime booted.
	 * @return void
	 */
	public static function maybe_run( $optional_runtime_active ) {
		if ( $optional_runtime_active ) {
			delete_option( 'voidpulse_downgrade_checked' );
			return;
		}
		$signature = VOIDPULSE_VERSION . ':' . OwnershipRegistry::signature( 'optional' );
		if ( $signature === get_option( 'voidpulse_downgrade_checked' ) ) {
			return;
		}
		OwnershipRegistry::unschedule( 'optional' );
		update_option( 'voidpulse_downgrade_checked', $signature, false );
	}
}
