<?php

namespace ConflictRadar\Core;

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

/**
 * Runs on register_deactivation_hook. Clears scheduled cron jobs only — does not drop tables or delete options.
 */
class Deactivator {

	private const CRON_HOOKS = array(
		'conflict_radar_scan_logs',
		'conflict_radar_weekly_digest',
		'conflict_radar_purge_old_data',
	);

	public static function deactivate(): void {
		foreach ( self::CRON_HOOKS as $hook ) {
			$timestamp = wp_next_scheduled( $hook );

			while ( false !== $timestamp ) {
				wp_unschedule_event( $timestamp, $hook );
				$timestamp = wp_next_scheduled( $hook );
			}

			wp_clear_scheduled_hook( $hook );
		}

		// Correlation checks are scheduled per-event WITH args [event_id, check_minutes],
		// so wp_clear_scheduled_hook( $hook ) (empty args) would miss them. Clear every
		// queued check regardless of args so no monitoring window dangles after deactivation.
		wp_unschedule_hook( 'conflict_radar_correlation_check' );
	}
}
