<?php

declare(strict_types=1);

/** APO-195 Card 7 — GET /api/v1/content/pages/{pageId} */
final class MyronGetPageAction implements MyronAction
{
    public function __construct(private readonly MyronContentRepository $repo) {}
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/content/pages/{pageId}', method: 'GET',
            domain: 'content', resource: 'page', verb: 'get',
            inputSchema: ['type' => 'object', 'properties' => ['pageId' => ['type' => 'string']], 'required' => ['pageId']],
            outputSchema: ['type' => 'object', 'properties' => []],
            requiredScope: MyronApiScopes::CONTENT_READ,
            summary: 'Get a single page by ID — current draft + published version, content, meta.',
            audienceClass: 3,
            snapshotInclude: false,
            exposeToMcp: true,
        );
    }
    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $id = trim((string) ($input['pageId'] ?? ''));
        if ($id === '') return MyronActionResult::error('input_invalid', 'pageId is required.');
        $row = $this->repo->getEditablePage($id);
        if (!is_array($row)) return MyronActionResult::error('precondition_failed', 'Page not found.');
        return MyronActionResult::ok($row);
    }
}
