imports:
  - { resource: ../../../../src/Backoffice/Shared/Infrastructure/Symfony/DependencyInjection/backoffice_services.yaml }
  - { resource: ../../../../src/Web/Shared/Infrastructure/Symfony/DependencyInjection/web_services.yaml }

services:
  _defaults:
    autoconfigure: true
    autowire: true

  # Configure
  _instanceof:
    Lehitgaber\Shared\Domain\Bus\Event\DomainEventSubscriber:
      tags: ['lehitgaber.domain_event_subscriber']

    Lehitgaber\Shared\Domain\Bus\Command\CommandHandler:
      tags: ['lehitgaber.command_handler']

    Lehitgaber\Shared\Domain\Bus\Query\QueryHandler:
      tags: ['lehitgaber.query_handler']

  Lehitgaber\Apps\Backoffice\Frontend\Controller\:
    resource: '../src/Controller'
    tags: ['controller.service_arguments']


  # Wire
  Lehitgaber\Shared\:
    resource: '../../../../src/Shared'

  Lehitgaber\Backoffice\:
    resource: '../../../../src/Backoffice'

  Lehitgaber\Web\:
    resource: '../../../../src/Web'

  # -- TAGGING --
  Lehitgaber\Shared\Infrastructure\Bus\Event\InMemory\InMemorySymfonyEventBus:
    arguments: [!tagged lehitgaber.domain_event_subscriber]
    lazy: true

  Lehitgaber\Shared\Infrastructure\Bus\Event\DomainEventMapping:
    arguments: [!tagged lehitgaber.domain_event_subscriber]

  Lehitgaber\Shared\Infrastructure\Bus\Event\DomainEventSubscriberLocator:
    arguments: [!tagged lehitgaber.domain_event_subscriber]

  Lehitgaber\Shared\Infrastructure\Doctrine\DatabaseConnections:
    arguments: [!tagged lehitgaber.database_connection]

  Lehitgaber\Shared\Infrastructure\Symfony\ApiExceptionListener:
    tags:
      - { name: kernel.event_listener, event: kernel.exception, method: onException }

  Lehitgaber\Shared\Infrastructure\Symfony\AddJsonBodyToRequestListener:
    tags:
      - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }


  # -- APP DEFINITIONS --
  # Command/Query Handlers
  Lehitgaber\Shared\Infrastructure\Bus\Command\InMemorySymfonyCommandBus:
    arguments: [!tagged lehitgaber.command_handler]

  Lehitgaber\Shared\Infrastructure\Bus\Query\InMemorySymfonyQueryBus:
    arguments: [!tagged lehitgaber.query_handler]

  # RabbitMQ
  Lehitgaber\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqConnection:
    arguments:
      - host: '%env(RABBITMQ_HOST)%'
        port: '%env(RABBITMQ_PORT)%'
        vhost: '%env(RABBITMQ_MOOC_VHOST)%'
        login: '%env(RABBITMQ_LOGIN)%'
        password: '%env(RABBITMQ_PASSWORD)%'
        read_timeout: 2
        write_timeout: 2
        connect_timeout: 5

  Lehitgaber\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqEventBus:
    arguments: ['@Lehitgaber\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqConnection', '%env(RABBITMQ_EXCHANGE)%']

  Lehitgaber\Shared\Infrastructure\Elasticsearch\ElasticsearchClient:
    factory: '@Lehitgaber\Shared\Infrastructure\Elasticsearch\ElasticsearchClientFactory'
    arguments:
      - '%env(BACKOFFICE_ELASTICSEARCH_HOST)%'
      - '%env(BACKOFFICE_ELASTICSEARCH_INDEX_PREFIX)%'
      - '%kernel.project_dir%/../../../databases/backoffice'
      - '%env(APP_ENV)%'
    public: true

  # -- IMPLEMENTATIONS SELECTOR --
  Lehitgaber\Shared\Domain\Bus\Event\EventBus: '@Lehitgaber\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqEventBus'
  Lehitgaber\Backoffice\Courses\Domain\BackofficeCourseRepository: '@Lehitgaber\Backoffice\Courses\Infrastructure\Persistence\ElasticsearchBackofficeCourseRepository'

twig:
  default_path: '%kernel.project_dir%/templates'
  strict_variables: true
  globals:
    flash: '@Lehitgaber\Shared\Infrastructure\Symfony\FlashSession'
