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

use ShopyPress\Jobs\Cron;
use ShopyPress\Jobs\SyncProducts;
use ShopyPress\Models\SyncState;

class ActionCron implements IHook {

    static function register() {
        add_action(Cron::SHOPYPRESS_HEARTBEAT, [self::class, 'on_shopypress_heartbeat']);
    }

    static function on_shopypress_heartbeat() {
        // Check if there's an active sync process
        $state = SyncState::load();

        // Continue existing sync if working
        if ($state !== null && $state->isWorking()) {
            $job = new SyncProducts();
            $job->run();
            return;
        }
    }
}
