<?php

declare(strict_types=1);

namespace App\Framework\Mcp;

use App\Framework\Core\AttributeMapper;
use App\Framework\Reflection\WrappedReflectionClass;
use App\Framework\Reflection\WrappedReflectionMethod;

final readonly class McpResourceMapper implements AttributeMapper
{
    public function getAttributeClass(): string
    {
        return McpResource::class;
    }

    public function map(WrappedReflectionClass|WrappedReflectionMethod $reflectionTarget, object $attributeInstance): ?array
    {
        if (! $reflectionTarget instanceof WrappedReflectionMethod || ! $attributeInstance instanceof McpResource) {
            return null;
        }

        $class = $reflectionTarget->getDeclaringClass();

        return [
            'uri' => $attributeInstance->uri,
            'name' => $attributeInstance->name ?: $attributeInstance->uri,
            'description' => $attributeInstance->description,
            'mimeType' => $attributeInstance->mimeType,
            'class' => $class->getFullyQualified(),
            'method' => $reflectionTarget->getName(),
        ];
    }
}
