<?php

declare(strict_types=1);

namespace App\Framework\Queue\Exceptions;

use App\Framework\Exception\Core\QueueErrorCode;
use App\Framework\Exception\ExceptionContext;

/**
 * Exception thrown when circular dependencies are detected in job chains
 */
final class CircularDependencyException extends QueueException
{
    public static function inChain(string $chainId, array $circularDependencies = []): self
    {
        $context = ExceptionContext::forOperation('chain.validate', 'JobChainExecutionCoordinator')
            ->withData([
                'chain_id' => $chainId,
                'circular_dependencies' => $circularDependencies,
            ]);

        return self::create(
            QueueErrorCode::CIRCULAR_DEPENDENCY,
            "Chain '{$chainId}' has circular dependencies",
            $context
        );
    }
}
