<?php

declare(strict_types=1);

/**
 * APO-193 Card 9 — Get a single footer variant.
 *
 * URI:   GET /api/v1/design/footers/{variantId}
 * Scope: design.read
 */
final class MyronGetFooterAction implements MyronAction
{
    public function __construct(
        private readonly MyronFooterDesignRepository $footers,
    ) {
    }

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri:           '/api/v1/design/footers/{variantId}',
            method:        'GET',
            domain:        'design',
            resource:      'footer',
            verb:          'get',
            inputSchema:   [
                'type'       => 'object',
                'properties' => ['variantId' => ['type' => 'string']],
                'required'   => ['variantId'],
            ],
            outputSchema:  ['type' => 'object', 'properties' => []],
            requiredScope:   MyronApiScopes::DESIGN_READ,
            summary:         'Get a single footer variant row by variant ID. Returns `variant_id` (machine code) and `variant_label` (human-readable) alongside activation, default, and zone configuration state.',
            sideEffects:     [],
            preconditions:   ['variant exists'],
            postconditions:  [],
            audienceClass:   3,
            adminAliases:    [],
            snapshotInclude: false,
            exposeToMcp:     true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $variantId = trim((string) ($input['variantId'] ?? ''));
        if ($variantId === '') {
            return MyronActionResult::error('input_invalid', 'variantId is required.');
        }
        try {
            return MyronActionResult::ok((array) $this->footers->getByVariantId($variantId));
        } catch (Throwable $e) {
            return MyronActionResult::error('precondition_failed', $e->getMessage());
        }
    }
}
