<?php

declare(strict_types=1);

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

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/design/document-templates', method: 'GET',
            domain: 'design', resource: 'document-template', verb: 'list',
            inputSchema: [
                'type' => 'object',
                'properties' => ['activeOnly' => ['type' => 'boolean']],
            ],
            outputSchema: ['type' => 'object', 'properties' => ['items' => ['type' => 'array']]],
            requiredScope: MyronApiScopes::DESIGN_READ,
            summary: 'List document templates (operator-uploaded saved archetypes).',
            audienceClass: 3,
            snapshotInclude: true, snapshotKey: 'design.documentTemplates',
            exposeToMcp: true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $activeOnly = (bool) ($input['activeOnly'] ?? false);
        return MyronActionResult::ok(['items' => $this->repo->listTemplates($activeOnly)]);
    }
}
