<?php

declare(strict_types=1);

namespace App\Framework\Queue\Initializers;

use App\Framework\Database\ConnectionInterface;
use App\Framework\Database\EntityManager;
use App\Framework\DI\Container;
use App\Framework\DI\Initializer;
use App\Framework\Queue\Contracts\JobProgressTrackerInterface;
use App\Framework\Queue\Services\DatabaseJobProgressTracker;
use App\Framework\Queue\Services\ProgressManager;

/**
 * Initialize job progress tracking services
 */
final readonly class ProgressTrackingInitializer
{
    #[Initializer]
    public function __invoke(Container $container): JobProgressTrackerInterface
    {
        // Create progress tracker implementation
        $progressTracker = new DatabaseJobProgressTracker(
            connection: $container->get(ConnectionInterface::class),
            entityManager: $container->get(EntityManager::class)
        );

        // Register progress manager
        $progressManager = new ProgressManager(
            progressTracker: $progressTracker
        );
        $container->instance(ProgressManager::class, $progressManager);

        return $progressTracker;
    }
}
