<?php

declare(strict_types=1);

/*
 * This file is part of the Serenity package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Serenity\CoreBundle;

use Serenity\CoreBundle\DependencyInjection\DoctrineRlsPass;
use Serenity\CoreBundle\DependencyInjection\TwigOverridePass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

class SerenityCoreBundle extends AbstractBundle
{
    /** @param array<string, mixed> $config */
    public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->import(__DIR__.'/../config/services.yaml');
    }

    public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->import(__DIR__.'/../config/packages/auto/*.yaml');
        /**
         * @var array<string> $bundles
         */
        $bundles = $builder->getParameter('kernel.bundles');
        if (!isset($bundles['SerenityAuthBundle'])) {
            $container->import(__DIR__.'/../config/packages/manual/security.yaml');
        }
    }

    public function build(ContainerBuilder $container): void
    {
        // 👉 Ajoute ton CompilerPass ici
        $container->addCompilerPass(new DoctrineRlsPass());
        $container->addCompilerPass(new TwigOverridePass());
    }
}
