<?php

declare(strict_types=1);

/**
 * APO-196 Card 2 — Mail action service.
 *
 * 2 verbs: save-mail-settings, send-test-mail.
 *
 * SMTP credential fields are exposeToMcp:false by policy (the action exists
 * for completeness but MCP clients see the sanitised read instead). Test-mail
 * is exposeToMcp:true — useful for AI clients to confirm setup.
 */
final class MyronMailActionService
{
    public function __construct(
        private readonly MyronMailSettingsRepository $settings,
        private readonly MyronMailTestService $testService,
    ) {
    }

    /**
     * @param array<string, mixed> $input
     * @return array{saved: bool}
     */
    public function saveSettings(array $input, MyronActionCallerContext $caller): array
    {
        $this->settings->saveSettings($input);
        return ['saved' => true];
    }

    /**
     * @return array{recipient: string}
     */
    public function sendTest(MyronActionCallerContext $caller): array
    {
        $recipient = (string) $this->testService->sendToConfiguredAddress();
        return ['recipient' => $recipient];
    }
}
