<?php

namespace App\Services\Queue;

use RuntimeException;

/**
 * Thrown when a feature wants to dispatch work to a queue that has no
 * live worker consuming it. Carries the queue name and a human-readable
 * fix hint so HTTP controllers can map it to a 503 with a clear body
 * instead of a generic 500.
 *
 * Catch this specifically before the catch-all in API controllers /
 * Livewire components — that way the user sees "the worker is not
 * running, here's how to start it" instead of "Something went wrong".
 */
class QueueWorkerDownException extends RuntimeException
{
    public function __construct(public readonly string $queueName)
    {
        parent::__construct(
            "The background queue worker for \"{$queueName}\" is not running. "
            . "Start it with: php artisan queue:work --queue={$queueName},default — "
            . "or check that your scheduler / supervisor / cron is configured "
            . "(see Documentation → Installation → Queue & Cron Setup)."
        );
    }

    public function userMessage(): string
    {
        return $this->getMessage();
    }
}
