<?php
/**
 * Detection Component
 *
 * Handles the abandoned cart detection heartbeat cron job.
 *
 * @package EDD\Pro\CartRecovery\Cron\Components
 * @since   3.6.5
 */

namespace EDD\Pro\CartRecovery\Cron\Components;

use EDD\Cron\Components\Component;
use EDD\Pro\CartRecovery\Jobs\Detection as DetectionJob;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

/**
 * Detection Component Class
 *
 * Subscribes to the detection heartbeat hook and delegates to the detection job.
 *
 * @since 3.6.5
 */
class Detection extends Component {

	/**
	 * The unique identifier for this component.
	 *
	 * @since 3.6.5
	 * @var string
	 */
	protected static $id = 'acr_detection';

	/**
	 * Get the subscribed events for detection jobs.
	 *
	 * @since 3.6.5
	 *
	 * @return array The array of hook => method mappings.
	 */
	public static function get_subscribed_events(): array {
		return array(
			'edd_acr_detection_heartbeat' => 'handle_detection',
		);
	}

	/**
	 * Handle detection heartbeat job.
	 *
	 * @since 3.6.5
	 *
	 * @return void
	 */
	public function handle_detection(): void {
		DetectionJob::handle();
	}
}
