<?php

declare(strict_types=1);

/**
 * APO-193 Card 9 — List registered sections.
 *
 * URI:   GET /api/v1/design/sections
 * Scope: design.read
 */
final class MyronListSectionsAction implements MyronAction
{
    public function __construct(
        private readonly MyronSectionRegistryRepository $sections,
    ) {
    }

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri:           '/api/v1/design/sections',
            method:        'GET',
            domain:        'design',
            resource:      'section',
            verb:          'list',
            inputSchema:   ['type' => 'object', 'properties' => []],
            outputSchema:  [
                'type'       => 'object',
                'properties' => ['items' => ['type' => 'array']],
            ],
            requiredScope:   MyronApiScopes::DESIGN_READ,
            summary:         'List registered section templates and their declared keys, slot bindings, and governance metadata.',
            sideEffects:     [],
            preconditions:   [],
            postconditions:  [],
            audienceClass:   3,
            adminAliases:    [],
            snapshotInclude: true,
            snapshotKey:     'design.sections',
            exposeToMcp:     true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $items = method_exists($this->sections, 'listSections')
            ? (array) $this->sections->listSections()
            : [];
        return MyronActionResult::ok(['items' => $items]);
    }
}
