<?php

declare(strict_types=1);

/** APO-196 Card 3 — POST /api/v1/administration/updates/dismiss (exposeToMcp:true, APO-205-007). */
final class MyronDismissRemoteApplicationUpdateAction implements MyronAction
{
    public function __construct(private readonly MyronSiteSetupActionService $service) {}
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/administration/updates/dismiss', method: 'POST',
            domain: 'administration', resource: 'application-update', verb: 'dismiss',
            inputSchema: [
                'type' => 'object',
                'properties' => ['version' => ['type' => 'string']],
                'required' => ['version'],
            ],
            outputSchema: ['type' => 'object', 'properties' => ['dismissedVersion' => ['type' => 'string']]],
            requiredScope: MyronApiScopes::ADMINISTRATION_WRITE,
            summary: 'Dismiss the available remote application update for a specific version.',
            sideEffects: ['updates remote_update_state row'],
            preconditions: ['caller is administrator'],
            postconditions: ['version is dismissed; will not surface until newer version available'],
            audienceClass: 4, adminAliases: ['dismiss-remote-application-update'],
            snapshotInclude: false, exposeToMcp: true,
        );
    }
    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try { return MyronActionResult::ok($this->service->dismissRemoteApplicationUpdate((string) ($input['version'] ?? ''), $caller)); }
        catch (MyronActionPreconditionError $e) { return MyronActionResult::error('precondition_failed', $e->getMessage()); }
        catch (InvalidArgumentException $e) { return MyronActionResult::error('input_invalid', $e->getMessage()); }
        catch (Throwable $e) { return MyronActionResult::error('business_rule_failed', $e->getMessage()); }
    }
}
