<?php
/**
 * Cleanup Component
 *
 * Handles the cleanup of expired carts and email records.
 *
 * @package EDD\Pro\CartRecovery\Cron\Components
 * @copyright Copyright (c) 2026, Sandhills Development, LLC
 * @since   3.6.5
 */

namespace EDD\Pro\CartRecovery\Cron\Components;

use EDD\Cron\Components\Component;

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

/**
 * Cleanup Component Class
 *
 * Subscribes to the cleanup hook and delegates to the cleanup job.
 * Also queues the next cleanup run after completion.
 *
 * @since 3.6.5
 */
class Cleanup extends Component {

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

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

	/**
	 * Handle cleanup job.
	 *
	 * @since 3.6.5
	 *
	 * @return void
	 */
	public function handle_cleanup(): void {
		\EDD\Pro\CartRecovery\Jobs\Cleanup::handle();
	}
}
