<?php

declare(strict_types=1);

namespace App\Framework\Reflection;

use ReflectionParameter;

final readonly class WrappedReflectionParameter
{
    public function __construct(
        public ReflectionParameter $reflection
    ) {}

    public function getName(): string
    {
        return $this->reflection->getName();
    }

    public function getTypeName(): ?string
    {
        $type = $this->reflection->getType();
        return $type ? $type->getName() : null;
    }

    public function isBuiltin(): bool
    {
        $type = $this->reflection->getType();
        return $type ? $type->isBuiltin() : true;
    }

    public function isOptional(): bool
    {
        return $this->reflection->isOptional();
    }

    public function hasDefaultValue(): bool
    {
        return $this->reflection->isDefaultValueAvailable();
    }

    public function getDefaultValue(): mixed
    {
        return $this->reflection->isDefaultValueAvailable()
            ? $this->reflection->getDefaultValue()
            : null;
    }

    public function allowsNull(): bool
    {
        return $this->reflection->allowsNull();
    }

    public function getPosition(): int
    {
        return $this->reflection->getPosition();
    }

    // Convenience-Methode für DI
    public function toArray(): array
    {
        return [
            'name' => $this->getName(),
            'type' => $this->getTypeName(),
            'isBuiltin' => $this->isBuiltin(),
            'allowsNull' => $this->allowsNull(),
            'isOptional' => $this->isOptional(),
            'hasDefaultValue' => $this->hasDefaultValue(),
            'default' => $this->getDefaultValue(),
            'position' => $this->getPosition(),
        ];
    }
}
