<?php

declare(strict_types=1);

namespace Spiral\Core\Exception\Container;

/**
 * @deprecated
 */
class ArgumentException extends AutowireException
{
    /**
     * @param \ReflectionParameter $parameter Parameter caused error.
     * @param \ReflectionFunctionAbstract $context Context method or constructor or function.
     */
    public function __construct(
        protected \ReflectionParameter $parameter,
        protected \ReflectionFunctionAbstract $context,
        ?\Throwable $previous = null,
    ) {
        $name = $context->getName();
        if ($context instanceof \ReflectionMethod) {
            $name = $context->class . '::' . $name;
        }

        parent::__construct(
            \sprintf("Unable to resolve '%s' argument in '%s'", $parameter->name, $name),
            previous: $previous,
        );
    }

    public function getParameter(): \ReflectionParameter
    {
        return $this->parameter;
    }

    public function getContext(): \ReflectionFunctionAbstract
    {
        return $this->context;
    }
}
