imports:
  - { 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\Web\Backend\Controller\:
      resource: '../src/Controller'
      tags: ['controller.service_arguments']

    Lehitgaber\Apps\Web\Backend\Command\:
      resource: '../src/Command'
      tags: ['console.command']

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

  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\AddJsonBodyToRequestListener:
    tags:
      - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

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


  # -- 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\Bus\Event\RabbitMq\RabbitMqDomainEventsConsumer:
    arguments:
      - '@Lehitgaber\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqConnection'
      - '@Lehitgaber\Shared\Infrastructure\Bus\Event\DomainEventJsonDeserializer'
      - '%env(RABBITMQ_EXCHANGE)%'
      - '%env(RABBITMQ_MAX_RETRIES)%'

  Lehitgaber\Apps\Web\Backend\Command\DomainEvents\RabbitMq\ConfigureRabbitMqCommand:
    arguments:
      - '@Lehitgaber\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqConfigurer'
      - '%env(RABBITMQ_EXCHANGE)%'
      - !tagged codely.domain_event_subscriber


  # -- IMPLEMENTATIONS SELECTOR --
  Lehitgaber\Shared\Domain\Bus\Event\EventBus: '@Lehitgaber\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqEventBus'
