<?php

declare(strict_types=1);

namespace App\Framework\Queue\Initializers;

use App\Framework\Database\ConnectionInterface;
use App\Framework\DI\Container;
use App\Framework\DI\Initializer;
use App\Framework\Logging\Logger;
use App\Framework\Queue\Interfaces\DistributedLockInterface;
use App\Framework\Queue\Services\FailoverRecoveryService;
use App\Framework\Queue\Services\JobDistributionService;
use App\Framework\Queue\Services\WorkerHealthCheckService;
use App\Framework\Queue\Services\WorkerRegistry;

/**
 * Failover Recovery Service Initializer
 */
final readonly class FailoverRecoveryInitializer
{
    #[Initializer]
    public function __invoke(Container $container): FailoverRecoveryService
    {
        $workerRegistry = $container->get(WorkerRegistry::class);
        $jobDistributionService = $container->get(JobDistributionService::class);
        $healthCheckService = $container->get(WorkerHealthCheckService::class);
        $distributedLock = $container->get(DistributedLockInterface::class);
        $connection = $container->get(ConnectionInterface::class);
        $logger = $container->get(Logger::class);

        return new FailoverRecoveryService(
            workerRegistry: $workerRegistry,
            jobDistributionService: $jobDistributionService,
            healthCheckService: $healthCheckService,
            distributedLock: $distributedLock,
            connection: $connection,
            logger: $logger
        );
    }
}
