<?php

namespace App\Services\Communications\Providers\Fakes;

use App\Contracts\Communications\EmailChannelProvider;
use App\Enum\Contact\MessageProvider;
use App\Models\Contact\Hub\ContactMessage;
use App\ValueObjects\Communications\ProviderSendResult;

/**
 * In-memory fake for local development / future tests.  Records each send
 * without making any network calls; returns a deterministic provider_message_id.
 */
class FakeEmailChannelProvider implements EmailChannelProvider
{
    /** @var array<int, array{message: ContactMessage, id: string}> */
    public array $sent = [];

    public function identifier(): MessageProvider
    {
        return MessageProvider::SENDGRID;
    }

    public function send(ContactMessage $message): ProviderSendResult
    {
        $id = 'fake-email-' . $message->id . '-' . uniqid();
        $this->sent[] = ['message' => $message, 'id' => $id];

        return new ProviderSendResult(
            providerMessageId: $id,
            payload: ['fake' => true, 'to' => $message->recipient_email],
            accepted: true,
        );
    }
}
