<?php

namespace AutoAdmin\Bundle;

use AutoAdmin\Bundle\Admin\DependencyInjection\Compiler\ControllerCompilerPass as AdminControllerCompilerPass;
use AutoAdmin\Bundle\Admin\DependencyInjection\Compiler\ExtraConfigCompilerPass;
use AutoAdmin\Bundle\Admin\DependencyInjection\Compiler\TypeGuesserCompilerPass;
use AutoAdmin\Bundle\BrickBuilder\DependencyInjection\Compiler\BrickBuilderRepositoryCompilerPass;
use AutoAdmin\Bundle\BrickBuilder\DependencyInjection\Compiler\BrickConfigCompilerPass;
use AutoAdmin\Bundle\BrickBuilder\DependencyInjection\Compiler\BrickHandlerCompilerPass;
use AutoAdmin\Bundle\Content\DependencyInjection\Compiler\DuplicatorCompilerPass;
use AutoAdmin\Bundle\Seo\DependencyInjection\Compiler\ExtractorCompilerPass;
use AutoAdmin\Bundle\Seo\DependencyInjection\Compiler\GeneratorCompilerPass;
use AutoAdmin\Bundle\Seo\DependencyInjection\Compiler\SchemaBuilderCompilerPass;
use AutoAdmin\Bundle\Media\DependencyInjection\Compiler\LiipResolverPass;
use AutoAdmin\Bundle\Media\DependencyInjection\Compiler\MapperConfigPass;
use AutoAdmin\Bundle\Media\DependencyInjection\Compiler\RegisterSluggerPass;
use AutoAdmin\Bundle\Content\DependencyInjection\Compiler\ControllerCompilerPass as ContentControllerCompilerPass;
use AutoAdmin\Bundle\Content\DependencyInjection\Compiler\ContentRepositoryCompilerPass;
use AutoAdmin\Bundle\Content\DependencyInjection\Compiler\TwigGlobalsCompilerPass;
use AutoAdmin\Bundle\Content\Event\ContentEvents;
use AutoAdmin\Bundle\Content\Event\ContentMatchEvent;
use AutoAdmin\Bundle\Content\Event\ContentMetadataEvent;
use AutoAdmin\Bundle\Content\Event\PostContentMetadataEvent;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\EventDispatcher\DependencyInjection\AddEventAliasesPass;

class AutoAdminBundle extends Bundle
{
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        // admin
        $container->addCompilerPass(new ExtraConfigCompilerPass());
        $container->addCompilerPass(new TypeGuesserCompilerPass());
        $container->addCompilerPass(new AdminControllerCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 100);

        // content
        $container->addCompilerPass(new TwigGlobalsCompilerPass());
        $container->addCompilerPass(new ContentRepositoryCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -10);
        $container->addCompilerPass(new ContentControllerCompilerPass());
        $container->addCompilerPass(new DuplicatorCompilerPass());


        $container->addCompilerPass(
            new AddEventAliasesPass(
                [
                    ContentMatchEvent::class => ContentEvents::MATCH,
                    ContentMetadataEvent::class => ContentEvents::METADATA,
                    PostContentMetadataEvent::class => ContentEvents::POST_METADATA,
                ]
            )
        );

        // brick builder
        $container->addCompilerPass(new BrickConfigCompilerPass());
        $container->addCompilerPass(new BrickHandlerCompilerPass());
        $container->addCompilerPass(new BrickBuilderRepositoryCompilerPass());

        // media
        $container->addCompilerPass(new RegisterSluggerPass());
        $container->addCompilerPass(new MapperConfigPass());
        $container->addCompilerPass(new LiipResolverPass());

        // seo
        $container->addCompilerPass(new ExtractorCompilerPass());
        $container->addCompilerPass(new GeneratorCompilerPass());
        $container->addCompilerPass(new SchemaBuilderCompilerPass());
    }


}
