<?php

declare(strict_types=1);

final class MailDispatchResult
{
    public function __construct(
        public readonly bool $ok,
        public readonly string $transportId,
        public readonly ?string $providerMessageId = null,
        public readonly ?string $error = null,
    ) {
    }

    public static function ok(string $transportId, ?string $providerMessageId = null): self
    {
        return new self(true, $transportId, $providerMessageId, null);
    }

    public static function failed(string $transportId, string $error): self
    {
        return new self(false, $transportId, null, $error);
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'ok' => $this->ok,
            'transportId' => $this->transportId,
            'providerMessageId' => $this->providerMessageId,
            'error' => $this->error,
        ];
    }
}
