<?php

declare(strict_types=1);
if (PHP_SAPI !== 'cli') {
    http_response_code(404);
    exit();
}
$root = dirname(__DIR__);
require $root . '/app/Services/DB.php';
require $root . '/app/Services/Migrations.php';
require $root . '/app/Services/I18n.php';
require $root . '/app/Services/AppSettings.php';
require $root . '/app/Services/Auth.php';
require $root . '/app/Services/BackupService.php';
require $root . '/app/Services/NotificationService.php';
Migrations::run($root . '/migrations');
I18n::setLocale(AppSettings::get('app_language'));
$result = NotificationService::send(false);
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;
exit(($result['sent'] ?? false) || in_array($result['reason'] ?? '', ['disabled', 'not_due'], true) ? 0 : 1);
