<?php
namespace ShopyPress\Jobs;
if ( ! defined( 'ABSPATH' ) ) exit;

use ShopyPress\Hooks\FilterCronSchedules;

class Cron {
    const SHOPYPRESS_HEARTBEAT = 'shopypress_heartbeat';

    static function addCronJobs(): void {
        if (!wp_next_scheduled(self::SHOPYPRESS_HEARTBEAT)) {
            $minutesInTheFuture = 5;
            wp_schedule_event(
                strtotime("+{$minutesInTheFuture} minutes", time()),
                FilterCronSchedules::EVERY_MINUTE,
                self::SHOPYPRESS_HEARTBEAT
            );
        }
    }

    static function removeCronJobs(): void {
        try {
            wp_clear_scheduled_hook(self::SHOPYPRESS_HEARTBEAT);
        } catch (\Throwable $th) {
            // Silently handle error
        }
    }
}
