<?php

declare(strict_types=1);

/** APO-194 Card 7 — GET /api/v1/design/navigation/versions/{versionId} */
final class MyronGetNavigationVersionAction implements MyronAction
{
    public function __construct(private readonly MyronNavigationDesignRepository $repo) {}

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/design/navigation/versions/{versionId}', method: 'GET',
            domain: 'design', resource: 'navigation-version', verb: 'get',
            inputSchema: ['type' => 'object', 'properties' => ['versionId' => ['type' => 'string']], 'required' => ['versionId']],
            outputSchema: ['type' => 'object', 'properties' => []],
            requiredScope: MyronApiScopes::DESIGN_READ,
            summary: 'Get a single navigation version by ID.',
            audienceClass: 3,
            snapshotInclude: false,
            exposeToMcp: true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $versionId = trim((string) ($input['versionId'] ?? ''));
        if ($versionId === '') return MyronActionResult::error('input_invalid', 'versionId is required.');
        $row = $this->repo->getById($versionId);
        if ($row === null) return MyronActionResult::error('precondition_failed', 'Version not found.');
        return MyronActionResult::ok((array) $row);
    }
}
