<?php

namespace Tests\Support\Auth;

use App\Services\OtpMailerInterface;

/**
 * In-memory OTP delivery for PHPUnit. Captures codes without SMTP.
 */
class ArrayOtpMailer implements OtpMailerInterface
{
    /** @var list<array{to: string, otp: string}> */
    public array $sent = [];

    public bool $configured = true;

    public function send(string $toEmail, string $otp): void
    {
        $this->sent[] = ['to' => $toEmail, 'otp' => $otp];
    }

    public function isConfigured(): bool
    {
        return $this->configured;
    }

    public function lastOtp(): ?string
    {
        if ($this->sent === []) {
            return null;
        }

        return $this->sent[array_key_last($this->sent)]['otp'];
    }

    public function lastTo(): ?string
    {
        if ($this->sent === []) {
            return null;
        }

        return $this->sent[array_key_last($this->sent)]['to'];
    }
}
