<?php
/**
 * Cron.
 *
 * @package flo-checkout
 */

namespace Flo_Checkout;

use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Modules\Cron_Module;
use Flo_Checkout\Gateways\Shift4_APM\Health_Check as Shift4_APM_Health_Check;

defined( 'ABSPATH' ) || exit;

/**
 * Class Cron
 */
class Cron {
	/**
	 * Set up hooks for Shared.
	 *
	 * @param string $service_name_underscored The service name underscored.
	 *
	 * @return void
	 */
	public static function setup_shared_hooks( string $service_name_underscored ): void {
		add_action(
			'northmill_online_shared_add_cron_events_' . $service_name_underscored,
			array( self::class, 'setup_cron' )
		);
	}

	/**
	 * Add multiple cron events.
	 *
	 * @return void
	 */
	public static function setup_cron(): void {
		self::setup_shift4_apm_cron();
	}

	/**
	 * Set up cron events for Shift4 APM.
	 *
	 * @return void
	 */
	public static function setup_shift4_apm_cron(): void {
		Shared::instance()->cron->add_cron_event(
			Shift4_APM_Health_Check::CRON_HEALTH_CHECK,
			Cron_Module::SCHEDULE_FIFTEEN_MINUTES,
			Shift4_APM_Health_Check::should_be_enabled(),
			array(
				array(
					Shift4_APM_Health_Check::class,
					'health_check',
				),
			)
		);

		add_action(
			Shift4_APM_Health_Check::CRON_SINGLE_HEALTH_CHECK,
			array(
				Shift4_APM_Health_Check::class,
				'run_single_health_check',
			),
			10,
			3
		);
	}
}
