<?php
declare(strict_types=1);

namespace FreshCloud\Mail\SmtpClient;

use DateTimeImmutable;

final readonly class SmtpResult
{
    public function __construct(
        public string $status,
        public ?string $messageId = null,
        public ?DateTimeImmutable $sentAt = null,
        public ?string $error = null,
    ) {
        if (!in_array($status, ['sent', 'queued', 'failed'])) {
            throw new \InvalidArgumentException('Invalid status');
        }
    }

    public static function sent(string $messageId): self
    {
        return new self('sent', $messageId, new DateTimeImmutable());
    }

    public static function queued(string $messageId): self
    {
        return new self('queued', $messageId, new DateTimeImmutable());
    }

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