<?php

declare(strict_types=1);

/** APO-194 Card 7 — GET /api/v1/design/document-templates/{templateId} */
final class MyronGetDocumentTemplateAction implements MyronAction
{
    public function __construct(private readonly MyronDocumentTemplateRepository $repo) {}

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

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $id = trim((string) ($input['templateId'] ?? ''));
        if ($id === '') return MyronActionResult::error('input_invalid', 'templateId is required.');
        $row = $this->repo->getTemplateById($id);
        if (!is_array($row)) return MyronActionResult::error('precondition_failed', 'Document template not found.');
        return MyronActionResult::ok($row);
    }
}
