<?php

declare(strict_types=1);

namespace App\Framework\DI\Exceptions;

use App\Framework\Exception\ExceptionContext;
use App\Framework\Exception\FrameworkException;

final class CyclicDependencyException extends FrameworkException
{
    public function __construct(
        array $dependencyChain,
        string $class,
        int $code = 0,
        ?\Throwable $previous = null
    ) {
        $context = ExceptionContext::forOperation('dependency_resolution', 'DI')
            ->withData([
                'dependencyChain' => $dependencyChain,
                'class' => $class,
            ]);

        parent::__construct(
            message: 'Zyklische Abhängigkeit entdeckt: ' . implode(' -> ', $dependencyChain) . " -> $class",
            context: $context,
            code: $code,
            previous: $previous
        );
    }
}
