<?php

declare(strict_types=1);

/**
 * APO-193 Card 9 — List token patches.
 *
 * URI:   GET /api/v1/design/tokens/patches
 * Scope: design.read
 */
final class MyronListTokenPatchesAction implements MyronAction
{
    public function __construct(
        private readonly MyronTokenPatchRepository $repository,
    ) {
    }

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri:           '/api/v1/design/tokens/patches',
            method:        'GET',
            domain:        'design',
            resource:      'token-patch',
            verb:          'list',
            inputSchema:   ['type' => 'object', 'properties' => []],
            outputSchema:  ['type' => 'object', 'properties' => ['patches' => ['type' => 'object']]],
            requiredScope:   MyronApiScopes::DESIGN_READ,
            summary:         'List all token override patches keyed by token name.',
            sideEffects:     [],
            preconditions:   [],
            postconditions:  [],
            audienceClass:   3,
            adminAliases:    [],
            snapshotInclude: true,
            snapshotKey:     'design.tokenPatches',
            exposeToMcp:     true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        return MyronActionResult::ok([
            'patches' => $this->repository->listPatchesByToken(),
        ]);
    }
}
