<?php

declare(strict_types=1);

namespace App\Framework\StaticSite;

use App\Framework\Attributes\Route;
use App\Framework\Attributes\StaticPage;
use App\Framework\Core\AttributeMapper;
use App\Framework\Reflection\WrappedReflectionClass;
use App\Framework\Reflection\WrappedReflectionMethod;

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

    public function map(WrappedReflectionClass|WrappedReflectionMethod $reflectionTarget, object $attributeInstance): ?array
    {
        if (! $reflectionTarget instanceof WrappedReflectionMethod) {
            return null; // StaticPage can only be applied to methods
        }

        $route = $reflectionTarget->getAttributes(Route::class);

        return [
            'route' => $route[0]->newInstance()->path,
        ];
    }
}
