<?php

declare(strict_types=1);

/**
 * APO-193 Card 4 — Dismiss a footer recommendation without applying it.
 *
 * URI:   POST /api/v1/design/footers/recommendations/dismiss
 * Scope: design.write
 */
final class MyronDismissFooterRecommendationAction implements MyronAction
{
    public function __construct(
        private readonly MyronFooterDesignActionService $service,
    ) {
    }

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri:           '/api/v1/design/footers/recommendations/dismiss',
            method:        'POST',
            domain:        'design',
            resource:      'footer-recommendation',
            verb:          'dismiss',
            inputSchema:   [
                'type'       => 'object',
                'properties' => [
                    'bundleId'  => ['type' => 'string'],
                    'variantId' => ['type' => 'string'],
                ],
                'required'   => ['bundleId', 'variantId'],
            ],
            outputSchema:  [
                'type'       => 'object',
                'properties' => [
                    'bundleId'  => ['type' => 'string'],
                    'variantId' => ['type' => 'string'],
                ],
            ],
            requiredScope:   MyronApiScopes::DESIGN_WRITE,
            summary:         'Dismiss a footer recommendation for the active site type bundle without applying it.',
            sideEffects:     ['writes recommendation dismissal state'],
            preconditions:   ['bundle exists', 'variant exists in valid variants'],
            postconditions:  ['recommendation marked dismissed; will not surface again unless reset'],
            audienceClass:   4,
            adminAliases:    ['dismiss-footer-recommendation'],
            snapshotInclude: false,
            exposeToMcp:     true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try {
            return MyronActionResult::ok($this->service->dismissRecommendation(
                (string) ($input['bundleId'] ?? ''),
                (string) ($input['variantId'] ?? ''),
                $caller
            ));
        } catch (InvalidArgumentException $e) {
            return MyronActionResult::error('input_invalid', $e->getMessage());
        } catch (Throwable $e) {
            return MyronActionResult::error('business_rule_failed', $e->getMessage());
        }
    }
}
