<?php

declare(strict_types=1);

/**
 * APO-193 Card 9 — List section component defaults.
 *
 * URI:   GET /api/v1/design/section-defaults
 * Scope: design.read
 */
final class MyronListSectionDefaultsAction implements MyronAction
{
    public function __construct(
        private readonly MyronSectionComponentDefaultsRepository $componentDefaults,
        private readonly MyronSectionContentDefaultsRepository $contentDefaults,
    ) {
    }

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri:           '/api/v1/design/section-defaults',
            method:        'GET',
            domain:        'design',
            resource:      'section-defaults',
            verb:          'list',
            inputSchema:   ['type' => 'object', 'properties' => []],
            outputSchema:  [
                'type'       => 'object',
                'properties' => [
                    'componentDefaults' => ['type' => 'array'],
                    'contentDefaults'   => ['type' => 'array'],
                ],
            ],
            requiredScope:   MyronApiScopes::DESIGN_READ,
            summary:         'List default content + editability for section templates — both per-component+variant scope and per-section-key scope.',
            sideEffects:     [],
            preconditions:   [],
            postconditions:  [],
            audienceClass:   3,
            adminAliases:    [],
            snapshotInclude: true,
            snapshotKey:     'design.sectionDefaults',
            exposeToMcp:     true,
        );
    }

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