<?php

namespace App\ValueObjects\Communications;

use App\Models\Contact\Hub\ContactMessage;

class DispatchResult
{
    public function __construct(
        public readonly ?ContactMessage $message,
        public readonly bool $queued,
        public readonly bool $wasSuppressed = false,
        public readonly bool $wasDeduped = false,
        public readonly bool $wasRateLimited = false,
        public readonly ?string $reason = null,
    ) {}

    public static function queued(ContactMessage $message): self
    {
        return new self($message, queued: true);
    }

    public static function suppressed(ContactMessage $message, string $reason): self
    {
        return new self($message, queued: false, wasSuppressed: true, reason: $reason);
    }

    public static function deduped(?ContactMessage $message, string $reason): self
    {
        return new self($message, queued: false, wasDeduped: true, reason: $reason);
    }

    public static function rateLimited(string $reason): self
    {
        return new self(null, queued: false, wasRateLimited: true, reason: $reason);
    }

    public static function invalidRecipient(string $reason): self
    {
        return new self(null, queued: false, reason: $reason);
    }
}
