<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Worker;

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

    public static function success(string $workerId, string $eventName): self
    {
        return new self(true, $workerId, $eventName, 'completed');
    }

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

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

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