<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\MainBundle;

use Chill\MainBundle\Cron\CronJobInterface;
use Chill\MainBundle\CRUD\CompilerPass\CRUDControllerCompilerPass;
use Chill\MainBundle\DependencyInjection\CompilerPass\ACLFlagsCompilerPass;
use Chill\MainBundle\DependencyInjection\CompilerPass\NotificationCounterCompilerPass;
use Chill\MainBundle\DependencyInjection\CompilerPass\SearchableServicesCompilerPass;
use Chill\MainBundle\DependencyInjection\CompilerPass\TimelineCompilerClass;
use Chill\MainBundle\DependencyInjection\CompilerPass\WidgetsCompilerPass;
use Chill\MainBundle\DependencyInjection\ConfigConsistencyCompilerPass;
use Chill\MainBundle\Notification\FlagProviders\NotificationFlagProviderInterface;
use Chill\MainBundle\Notification\NotificationHandlerInterface;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\MainBundle\Search\SearchApiInterface;
use Chill\MainBundle\Security\ProvideRoleInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverInterface;
use Chill\MainBundle\Security\Resolver\ScopeResolverInterface;
use Chill\MainBundle\Service\EntityInfo\ViewEntityInfoProviderInterface;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\UI\NotificationCounterInterface;
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

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

        $container->registerForAutoconfiguration(LocalMenuBuilderInterface::class)
            ->addTag('chill.menu_builder');
        $container->registerForAutoconfiguration(CenterResolverInterface::class)
            ->addTag('chill_main.center_resolver');
        $container->registerForAutoconfiguration(ScopeResolverInterface::class)
            ->addTag('chill_main.scope_resolver');
        $container->registerForAutoconfiguration(ChillEntityRenderInterface::class)
            ->addTag('chill.render_entity');
        $container->registerForAutoconfiguration(SearchApiInterface::class)
            ->addTag('chill.search_api_provider');
        $container->registerForAutoconfiguration(NotificationHandlerInterface::class)
            ->addTag('chill_main.notification_handler');
        $container->registerForAutoconfiguration(NotificationCounterInterface::class)
            ->addTag('chill.count_notification.user');
        $container->registerForAutoconfiguration(EntityWorkflowHandlerInterface::class)
            ->addTag('chill_main.workflow_handler');
        $container->registerForAutoconfiguration(CronJobInterface::class)
            ->addTag('chill_main.cron_job');
        $container->registerForAutoconfiguration(ViewEntityInfoProviderInterface::class)
            ->addTag('chill_main.entity_info_provider');
        $container->registerForAutoconfiguration(ProvideRoleInterface::class)
            ->addTag('chill_main.provide_role');
        $container->registerForAutoconfiguration(NotificationFlagProviderInterface::class)
            ->addTag('chill_main.notification_flag_provider');

        $container->addCompilerPass(new SearchableServicesCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
        $container->addCompilerPass(new ConfigConsistencyCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
        $container->addCompilerPass(new TimelineCompilerClass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
        $container->addCompilerPass(new WidgetsCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
        $container->addCompilerPass(new NotificationCounterCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
        $container->addCompilerPass(new ACLFlagsCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
        $container->addCompilerPass(new CRUDControllerCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
    }
}
