<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Dispatcher\Execution;

use PpPhp\Core\Platform\Event\Queue\DeferredEvent;
use PpPhp\Core\Platform\Event\Dispatcher\DispatcherResult;

final class DispatcherPipeline
{
    private array $stages = ['load', 'resolve', 'execute', 'retry', 'dead-letter', 'complete'];

    public function __construct(private readonly DispatcherWorker $worker = new DispatcherWorker()) {}

    public function stages(): array
    {
        return $this->stages;
    }

    public function process(DeferredEvent $event, ?callable $handler = null): DispatcherResult
    {
        return $this->worker->handle($event, $handler);
    }

    public function worker(): DispatcherWorker
    {
        return $this->worker;
    }
}
