<?php

declare(strict_types=1);

namespace App\Framework\Shutdown;

use App\Framework\Attributes\Initializer;
use App\Framework\DI\Container;
use App\Framework\Logging\Logger;

/**
 * Initializes the shutdown handler system
 *
 * Registers the ShutdownHandlerManager in the DI container and sets up
 * PHP's shutdown function to use the centralized handler management system.
 */
final readonly class ShutdownHandlerInitializer
{
    #[Initializer]
    public function __invoke(Container $container): void
    {
        // Create ShutdownHandlerManager instance
        $shutdownManager = new ShutdownHandlerManager(
            logger: $container->get(Logger::class)
        );

        // Register as singleton in container
        $container->singleton(ShutdownHandlerManager::class, $shutdownManager);

        // Register PHP shutdown function
        $shutdownManager->register();
    }
}
