#
# Module services
#
# Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
# See https://www.x-cart.com/license-agreement.html for license details.

services:
  _defaults:
    autowire: true

  XC\AutoImportBase\Messenger\Handler\ExecuteCommandHandler:
    tags:
      - {name: messenger.message_handler, transport: async_my_awesome_provider_commands}
      - {name: messenger.message_handler, transport: async_my_awesome_provider_images_commands}

  XCExample\AutomotiveImportExample\Core\Configuration\Configuration:
    class: XCExample\AutomotiveImportExample\Core\Configuration\Configuration
    public: true
    arguments:
      $rawConfigHelperClass: 'XCExample\AutomotiveImportExample\Core\Data\Helper\RawConfigHelper'

  xcexample.automotive_import_example.metadata_gateway:
    class: XC\AutoImportBase\Core\Metadata\DBMetadataGateway
    arguments:
      $metadataClassName: '\XCExample\AutomotiveImportExample\Model\Metadata'
    public: true

  xcexample.automotive_import_example.auth_service:
    class: XCExample\AutomotiveImportExample\Core\Auth\BearerAuthService
    arguments:
      $configuration: '@XCExample\AutomotiveImportExample\Core\Configuration\Configuration'

  XCExample\AutomotiveImportExample\Core\API\HttpClientFactory: ~
  xcexample.automotive_import_example.symfony.client:
    class: Symfony\Component\HttpClient\HttpClient
    arguments:
      $configuration: '@XCExample\AutomotiveImportExample\Core\Configuration\Configuration'
      $authService: '@xcexample.automotive_import_example.auth_service'
    factory: ['@XCExample\AutomotiveImportExample\Core\API\HttpClientFactory', 'createHttpClient']

  xcexample.automotive_import_example.api_service:
    class: XCExample\AutomotiveImportExample\Core\API\APIService
    arguments:
      $httpClient: '@xcexample.automotive_import_example.symfony.client'
  XCExample\AutomotiveImportExample\Core\API\APIGateway:
    class: XCExample\AutomotiveImportExample\Core\API\APIGatewayImplementation
    public: true
    arguments:
      $apiService: '@xcexample.automotive_import_example.api_service'

  XCExample\AutomotiveImportExample\Core\Task\LoadMyAwesomeProviderProductImagesTask:
    tags:
      - {name: kernel.event_listener, event: xcart.cronjob, method: handleTask}

  XCExample\AutomotiveImportExample\Core\Task\ImportScheduleTask:
    tags:
      - {name: kernel.event_listener, event: xcart.cronjob, method: handleTask}

  xcexample.automotive_import_example.logger:
    class: Psr\Log\LoggerInterface
    public: true
    factory: ['@XLite\Logger', getLogger]
    arguments:
      - 'XCExample-AutomotiveImportExampleData'

  xcexample.automotive_import_example.realtime_import_images:
    class: XC\AutoImportBase\Core\EventListener\RealtimeImportImages
    arguments:
      $blockClass: 'XCExample\AutomotiveImportExample\Model\MyAwesomeProviderBrand'
      $wrapperCommand: 'XCExample\AutomotiveImportExample\Messenger\Message\ExecuteImagesCommand'
      $logger: '@xcexample.automotive_import_example.logger'
    tags:
      - {name: kernel.event_listener, event: auto_import.product.update.after, method: onAfterProductUpdate}
      - {name: kernel.event_listener, event: auto_import.products.batch.finished, method: onProductsBatchFinished}

  xcexample.automotive_import_example.communication_logger:
    class: Psr\Log\LoggerInterface
    public: true
    factory: [ '@XLite\Logger', getLogger ]
    arguments:
      - 'XCExample-AutomotiveImportExample.communication'

  xcexample.automotive_import_example.mmy_validity_constraint:
    class: XC\AutoImportBase\Core\Command\Constraints\MMYSetupBlockImportConstraint
    public: true
    arguments:
      $vehicles:
        submodel: {make: "test", model: "test", year: 2000, submodel: "test"}

framework:
  messenger:
    transports:
      async_my_awesome_provider_commands:
        dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        serializer: XCart\Messenger\Serializer
        options:
          queue_name: my_awesome_provider
      async_my_awesome_provider_images_commands:
        dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        serializer: XCart\Messenger\Serializer
        options:
          queue_name: my_awesome_provider_images

    routing:
      'XCExample\AutomotiveImportExample\Messenger\Message\ExecuteCommand': async_my_awesome_provider_commands
      'XCExample\AutomotiveImportExample\Messenger\Message\ExecuteImagesCommand': async_my_awesome_provider_images_commands
