<?php

declare(strict_types=1);

namespace App\Framework\Notification\Channels;

use App\Framework\Notification\ValueObjects\NotificationChannel;

/**
 * Result of a channel delivery attempt
 */
final readonly class ChannelResult
{
    public function __construct(
        public NotificationChannel $channel,
        public bool $success,
        public ?string $errorMessage = null,
        public array $metadata = []
    ) {
    }

    public static function success(
        NotificationChannel $channel,
        array $metadata = []
    ): self {
        return new self(
            channel: $channel,
            success: true,
            metadata: $metadata
        );
    }

    public static function failure(
        NotificationChannel $channel,
        string $errorMessage,
        array $metadata = []
    ): self {
        return new self(
            channel: $channel,
            success: false,
            errorMessage: $errorMessage,
            metadata: $metadata
        );
    }

    public function isSuccess(): bool
    {
        return $this->success;
    }

    public function isFailure(): bool
    {
        return ! $this->success;
    }
}
