<?php

declare(strict_types=1);

namespace App\Framework\Retry;

use App\Framework\Core\Events\EventDispatcherInterface;
use App\Framework\DateTime\Clock;
use App\Framework\DI\Initializer;

/**
 * Initializer für das Retry-System
 *
 * Registriert RetryManager im DI-Container
 */
final readonly class RetryInitializer
{
    #[Initializer]
    public function __invoke(Clock $clock, ?EventDispatcherInterface $eventDispatcher = null): RetryManager
    {
        $retryManager = RetryManager::create($clock);

        if ($eventDispatcher !== null) {
            $retryManager = $retryManager->withEventDispatcher($eventDispatcher);
        }

        return $retryManager;
    }
}
