<?php

declare(strict_types=1);

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

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/design/templates/{templateId}/chrome', method: 'GET',
            domain: 'design', resource: 'template-chrome', verb: 'get',
            inputSchema: ['type' => 'object', 'properties' => ['templateId' => ['type' => 'string']], 'required' => ['templateId']],
            outputSchema: ['type' => 'object', 'properties' => []],
            requiredScope: MyronApiScopes::DESIGN_READ,
            summary: 'Get a template\'s chrome assignment (navigation version + footer variant bindings).',
            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->getForTemplate($id) ?? [];
        return MyronActionResult::ok((array) $row);
    }
}
