<?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\JobDistributionService;
use App\Framework\Queue\Services\WorkerRegistry;

/**
 * Job Distribution Service Initializer
 */
final readonly class JobDistributionInitializer
{
    #[Initializer]
    public function __invoke(Container $container): JobDistributionService
    {
        $workerRegistry = $container->get(WorkerRegistry::class);
        $distributedLock = $container->get(DistributedLockInterface::class);
        $connection = $container->get(ConnectionInterface::class);
        $logger = $container->get(Logger::class);

        return new JobDistributionService(
            workerRegistry: $workerRegistry,
            distributedLock: $distributedLock,
            connection: $connection,
            logger: $logger
        );
    }
}
