<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Consumer;

final class QueueConsumerResult
{
    public function __construct(
        private readonly bool $ok,
        private readonly string $eventName = '',
        private readonly string $workerId = '',
        private readonly bool $acknowledged = false,
        private readonly bool $failed = false,
        private readonly string $message = ''
    ) {}

    public static function createAcknowledged(string $eventName, string $workerId): self
    {
        return new self(true, $eventName, $workerId, true, false, 'acknowledged');
    }

    public static function createEmpty(): self
    {
        return new self(true, '', '', false, false, 'empty');
    }

    public static function createFailed(string $eventName, string $workerId, string $message): self
    {
        return new self(false, $eventName, $workerId, false, true, $message);
    }

    public function ok(): bool { return $this->ok; }
    public function acknowledged(): bool { return $this->acknowledged; }
    public function failed(): bool { return $this->failed; }

    public function toArray(): array
    {
        return [
            'ok' => $this->ok,
            'eventName' => $this->eventName,
            'workerId' => $this->workerId,
            'acknowledged' => $this->acknowledged,
            'failed' => $this->failed,
            'message' => $this->message,
        ];
    }
}
