<?php
/**
 * Background cron worker (CLI or secured HTTP). Does not block bot.php.
 */
define('WIZWIZ_CRON', true);
include_once __DIR__ . '/../config.php';

$cliToken = (PHP_SAPI === 'cli') ? ($argv[1] ?? '') : '';
$httpOk = (PHP_SAPI !== 'cli') && CronScheduler::isValidCronRequest();

if (PHP_SAPI === 'cli') {
    if (!CronScheduler::isValidCronRequest($cliToken)) {
        fwrite(STDERR, "Forbidden\n");
        exit(1);
    }
} elseif (!$httpOk) {
    http_response_code(403);
    exit('Forbidden');
}

CronScheduler::runDueTasks();
