<?php
require __DIR__ . '/../api/bootstrap.php';

use App\Services\WhatsAppQueueService;

try {
    $result = (new WhatsAppQueueService())->processQueue();
    echo '[' . date('Y-m-d H:i:s') . '] [Pyrk WhatsApp] ' . ($result['message'] ?? 'Queue worker completed.')
        . ' Sent: ' . (int)($result['sent'] ?? 0)
        . ' Retrying: ' . (int)($result['retried'] ?? 0)
        . ' Failed: ' . (int)($result['failed'] ?? 0)
        . PHP_EOL;
} catch (Throwable $e) {
    fwrite(STDERR, '[' . date('Y-m-d H:i:s') . '] [Pyrk WhatsApp] Worker failed: ' . $e->getMessage() . PHP_EOL);
    exit(1);
}
