<?php

declare(strict_types=1);

final class MyronGetVerificationSettingsAction implements MyronAction
{
    public function __construct(private readonly MyronVerificationSettingsRepository $repo)
    {
    }

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/administration/verification-settings',
            method: 'GET',
            domain: 'administration',
            resource: 'verification-settings',
            verb: 'get',
            inputSchema: ['type' => 'object', 'properties' => []],
            outputSchema: ['type' => 'object'],
            requiredScope: MyronApiScopes::ADMINISTRATION_READ,
            summary: 'Get form protection verification settings.',
            sideEffects: [],
            preconditions: ['caller holds administration.read'],
            postconditions: ['verification settings returned'],
            audienceClass: 3,
            exposeToMcp: true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $settings = $this->repo->getSettings();
        $settings['verification_turnstile_secret_key_configured'] = trim((string) ($settings['verification_turnstile_secret_key'] ?? '')) !== '';
        unset($settings['verification_turnstile_secret_key']);
        return MyronActionResult::ok(['settings' => $settings]);
    }
}

