<?php

declare(strict_types=1);

namespace App\Framework\Queue\Exceptions;

use App\Framework\Exception\Core\QueueErrorCode;
use App\Framework\Exception\ExceptionContext;
use App\Framework\Queue\ValueObjects\JobId;

/**
 * Exception thrown when a job cannot be found
 */
final class JobNotFoundException extends QueueException
{
    public static function byId(JobId $jobId): self
    {
        $context = ExceptionContext::forOperation('job.lookup', 'JobPersistenceLayer')
            ->withData([
                'job_id' => $jobId->toString(),
                'search_type' => 'by_id',
            ]);

        return self::create(
            QueueErrorCode::JOB_NOT_FOUND,
            "Job with ID '{$jobId->toString()}' not found",
            $context
        );
    }

    public static function inQueue(JobId $jobId, string $queueName): self
    {
        $context = ExceptionContext::forOperation('job.lookup', 'Queue')
            ->withData([
                'job_id' => $jobId->toString(),
                'queue_name' => $queueName,
                'search_type' => 'in_queue',
            ]);

        return self::create(
            QueueErrorCode::JOB_NOT_FOUND,
            "Job '{$jobId->toString()}' not found in queue '{$queueName}'",
            $context
        );
    }
}

