<?php

declare(strict_types=1);

namespace App\Framework\Random;

use App\Framework\DI\Container;
use App\Framework\DI\Initializer;
use App\Framework\Security\CsrfTokenGenerator;

final readonly class RandomGeneratorInitializer
{
    public function __construct(
        private Container $container
    ) {
    }

    /**
     * Initialize random-related services in the container.
     */
    #[Initializer]
    public function __invoke(): void
    {
        // Register core RandomGenerator
        $this->container->singleton(RandomGenerator::class, SecureRandomGenerator::class);

        // Register specific generators that depend on RandomGenerator
        $this->container->singleton(CsrfTokenGenerator::class, function (Container $container): CsrfTokenGenerator {
            return new CsrfTokenGenerator($container->get(RandomGenerator::class));
        });
    }
}
