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

parameters:
  atd.api_proxy_link.default: ""
  atd.api_proxy_link: "%env(default:atd.api_proxy_link.default:string:ATD_API_PROXY_LINK)%"

  atd.integration_name: !php/const XC\ATD\IntegrationSettings::SERVICE_NAME
  atd.cache_installation_spec_life_time_in_secs: 604800
  atd.retries_api_service_count: 5

services:
  _defaults:
    autowire: true
    autoconfigure: true

  XC\AutoImportBase\Messenger\Handler\ExecuteCommandHandler:
    tags:
      - {name: messenger.message_handler, transport: async_atd_commands}
      - {name: messenger.message_handler, transport: async_atd_vehicles_commands}
      - {name: messenger.message_handler, transport: async_atd_images_commands}

  XC\ATD\IntegrationSettings:
    class: XC\ATD\IntegrationSettings
    public: true
    tags: [{name: xc.autoimportbase.integration.settings}]
    arguments:
      $productsLimit: '%auto_trial.products_limit%'
      $metadataGateway: '@xc.atd.metadata_gateway'
      $updateOptionsHelper: '@xc.atd.product.update.options.helper'
      $blockRepo: '@xc.atd.repository.brand'
      $blockImport: '@xc.atd.brand_data_import'
      $brandsImportStatusStorage: '@xc.atd.brand_import_status_storage'
      $categoriesImportStatusStorage: '@xc.atd.categories_import_status_storage'
      $topMessageScheduler: '@xc.atd.top_message_scheduler'
      $logger: '@xc.atd.logger'
      $vehicleDataProvider: '@xc.atd.vehicle_data_provider'
      $rawMetadataCollection: '@xc.atd.raw_metadata_collection'
      $categoryMapRepo: '@xc.atd.repository.category_map'

  XC\ATD\Core\Data\Updater\CategoryMapUpdater:
    class: XC\ATD\Core\Data\Updater\CategoryMapUpdater
    public: true
    arguments:
      $categoryMapHelper: '@xc.atd.category.map.helper'
      $categoryMapUpdater: '@XC\AutoImportBase\Core\Data\Updater\CategoryMapUpdater'

  XC\ATD\Core\Data\Adapter\Category\ICategoryMapAdapter:
    class: XC\ATD\Core\Data\Adapter\Category\CategoryMap
    public: true

  XC\ATD\Core\Data\Adapter\Brand\IBrandAdapter:
    class: XC\ATD\Core\Data\Adapter\Brand\Brand
    public: true

  XC\ATD\Core\Data\Adapter\Product\IProductAdapter:
    class: XC\ATD\Core\Data\Adapter\Product\ProductAdapter
    public: true

  XC\ATD\Core\Data\Adapter\Product\ProductAdaptedConverter: ~

  XC\ATD\Core\Data\Adapter\Order\AdaptedOrderConverter: ~

  XC\ATD\Core\Data\Adapter\Order\AtdOrderRequestBuilder:
    class: XC\ATD\Core\Data\Adapter\Order\AtdOrderRequestBuilder
    public: true
    arguments:
      $metadataGateway: '@xc.atd.metadata_gateway'

  XC\ATD\Core\Data\Adapter\Order\IOrderAdapter:
    class: XC\ATD\Core\Data\Adapter\Order\AtdOrderAdapter
    public: true

  XC\ATD\Core\Data\Adapter\OrderDetails\OrderDetailsConverter: ~

  XC\ATD\Core\Data\Adapter\OrderDetails\IOrderDetailsAdapter:
    class: XC\ATD\Core\Data\Adapter\OrderDetails\OrderDetailsAdapter
    public: true

  XC\ATD\Core\API\CategoriesAPIGateway\ICategoriesAPIGateway:
    class: XC\ATD\Core\API\CategoriesAPIGateway\CategoriesAPIGatewayImplementation
    public: true

  XC\ATD\Core\API\BrandsAPIGateway\IBrandsAPIGateway:
    class: XC\ATD\Core\API\BrandsAPIGateway\BrandsAPIGatewayImplementation
    public: true
    arguments:
      $apiService: '@xc.atd.api_service'
      $brandDataBuilder: '@XC\ATD\Core\API\BrandsAPIGateway\DataBuilder\BrandDataBuilder'

  XC\ATD\Core\API\BrandsAPIGateway\DataBuilder\BrandDataBuilder:
    class: XC\ATD\Core\API\BrandsAPIGateway\DataBuilder\BrandDataBuilder
    public: true

  XC\ATD\Core\API\ProductsAPIGateway\ProductsAPIGateway:
    class: XC\ATD\Core\API\ProductsAPIGateway\ProductsAPIGatewayImplementation
    public: true
    arguments:
      $apiService: '@xc.atd.api_service'
      $productDataBuilder: '@XC\ATD\Core\API\ProductsAPIGateway\DataBuilder\ProductDataBuilder'

  XC\ATD\Core\API\ProductsAPIGateway\DataBuilder\ProductDataBuilder:
    class: XC\ATD\Core\API\ProductsAPIGateway\DataBuilder\ProductDataBuilder
    public: true

  XC\ATD\Core\API\VehicleAPIGateway\IVehiclesAPIGateway:
    class: XC\ATD\Core\API\VehicleAPIGateway\VehiclesAPIGatewayImplementation
    public: true
    arguments:
      $apiService: '@xc.atd.api_service'

  XC\ATD\Core\API\VehicleAPIGateway\DataBuilder\VehicleDataBuilder: ~
  XC\ATD\Core\API\VehicleAPIGateway\DataBuilder\VehicleTrimOptionsDataBuilder: ~
  XC\ATD\Core\API\VehicleAPIGateway\DataBuilder\VehicleInstallationSpecsDataBuilder: ~

  XC\ATD\Core\API\OrderAPIGateway\OrderAPIGateway:
    class: XC\ATD\Core\API\OrderAPIGateway\OrderAPIGatewayImplementation
    public: true
    arguments:
      $apiService: '@xc.atd.api_service'

  XC\ATD\Core\API\OrderAPIGateway\DataBuilder\OrderDataBuilder: ~

  xc.atd.repository.brand:
    class: XC\ATD\Model\Repo\AtdBrand
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - XC\ATD\Model\AtdBrand

  xc.atd.categories_import_status_storage:
    class: XC\AutoImportBase\Core\Data\Storage\SubBlockImportStatusStorage
    public: true
    arguments:
      $moduleId: 'XC-ATD'
      $optionName: 'importCategoriesStatus'
      $statusRepo: '@xc.autoimportbase.repository.sub_block_import_status'

  xc.atd.repository.category_map:
    class: XC\AutoImportBase\Model\Repo\AutoCategoryMap
    public: true
    factory: [ '@doctrine.orm.default_entity_manager', getRepository ]
    arguments:
      - XC\ATD\Model\CategoryMap

  xc.atd.xcart.repository.shipping.method:
    class: XLite\Model\Repo\Shipping\Method
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - XLite\Model\Shipping\Method

  xc.atd.xcart.repository.order.status.shipping:
    class: XLite\Model\Repo\Order\Status\Shipping
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - XLite\Model\Order\Status\Shipping

  xc.atd.xcart.repository.order:
    class: XLite\Model\Repo\Order
    public: true
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - XLite\Model\Order

  XC\ATD\Core\Configuration\Configuration:
    class: XC\ATD\Core\Configuration\Configuration
    public: true
    arguments:
      $rawConfigHelper: '@xc.atd.raw.config.helper'
      $currencyRepo: '@xc.autoimportbase.repository.currency'
      $apiProxyLink: '%atd.api_proxy_link%'

  xc.atd.raw.config.helper:
    class: XC\AutoImportBase\Core\Helper\RawConfigHelper
    public: true
    arguments:
      $integrationModuleId: 'XC-ATD'

  xc.atd.logger:
    class: Psr\Log\LoggerInterface
    public: true
    factory: ['@XLite\Logger', getLogger]
    arguments:
      - 'XC-ATD'

  xc.atd.vehicle_data_provider:
    class: XC\ATD\Core\Provider\ATDVehicleDataProvider
    public: true
    arguments:
      $configuration: '@XC\ATD\Core\Configuration\Configuration'
      $commonVehiclesImportStatusStorage: '@xc.atd.common_vehicle_import_status_storage'
      $mmyConstraint: '@xc.atd.mmy_validity_constraint'

  xc.atd.common_vehicle_import_status_storage:
    class: XC\AutoImportBase\Core\Data\Storage\SubBlockImportStatusStorage
    public: true
    arguments:
      $moduleId: 'XC-ATD'
      $optionName: 'commonVehiclesImportStatus'
      $statusRepo: '@xc.autoimportbase.repository.sub_block_import_status'

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

  xc.atd.metadata_gateway:
    class: XC\AutoImportBase\Core\Metadata\DBMetadataGateway
    arguments:
      $metadataClassName: '\XC\ATD\Model\Metadata'
    public: true

  xc.atd.product.update.options.helper:
    class: XC\AutoImportBase\Core\Data\Helper\ProductUpdateOptionsHelper
    arguments:
      $configuration: '@XC\ATD\Core\Configuration\Configuration'
    public: true

  xc.atd.brand_import_status_storage:
    class: XC\AutoImportBase\Core\Data\Storage\SubBlockImportStatusStorage
    public: true
    arguments:
      $moduleId: 'XC-ATD'
      $optionName: 'brandsImportStatus'
      $statusRepo: '@xc.autoimportbase.repository.sub_block_import_status'

  xc.atd.brand_data_import:
    class: XC\AutoImportBase\Core\Command\BlockImport\BlockImportEventsDecorator
    arguments:
      $blockImport: '@xc.atd.brand_data_import.inner'
      $constraintBuilder: '@xc.atd.brand_data_import.constraint_builder'
      $integration: '%atd.integration_name%'
    factory: ['@XC\AutoImportBase\Core\Command\BlockImport\DefaultDecoratedBlockImportFactory', 'create']

  xc.atd.brand_data_import.inner:
    class: XC\ATD\Core\Command\BlockImport\AtdBrandImport
    arguments:
      $metadataGateway: '@xc.atd.metadata_gateway'
      $productsChunkSize: 500

  xc.atd.brand_data_import.constraint_builder:
    class: XC\ATD\Core\Command\BlockImport\ConstraintBuilder

  XC\ATD\Core\Metadata\ISpecificLocalEntityGateway:
    class: XC\ATD\Core\Metadata\SpecificLocalEntityGateway
    public: true
    arguments:
      $localEntityGateway: '@xc.atd.local_entity_gateway'
      $metadataGateway: '@xc.atd.metadata_gateway'

  xc.atd.local_entity_gateway:
    class: XC\AutoImportBase\Core\Metadata\LocalEntityGateway
    public: true
    arguments:
      $metadataGateway: '@xc.atd.metadata_gateway'
      $rawMetadataCollection: '@xc.atd.raw_metadata_collection'

  xc.atd.top_message_scheduler:
    class: \XC\AutoImportBase\Core\Scheduler\TopMessageScheduler
    public: true
    arguments:
      $groupName: 'atdDataMessages'

  xc.atd.category.map.helper:
    class: XC\AutoImportBase\Core\Data\Helper\CategoryMapHelper
    public: true
    arguments:
      $addedEntityHelper: '@XC\AutoImportBase\Core\Data\Helper\KnownEntityHelper'
      $categoryMapRepo: '@xc.atd.repository.category_map'

  xc.atd.raw_metadata_collection:
    class: XC\AutoImportBase\Core\Metadata\RawMetadataCollection
    public: true
    arguments:
      $metadataGateway: '@xc.atd.metadata_gateway'

  xc.atd.auth_service:
    class: XC\ATD\Core\API\AuthService
    arguments:
      $configuration: '@XC\ATD\Core\Configuration\Configuration'

  xc.atd.communication_logger:
    class: XC\AutoImportBase\Core\API\CommunicationLogger
    public: true
    arguments:
      $logger: '@xc.atd.logger'
      $httpClient: '@xc.atd.symfony.client'

  xc.atd.api_service:
    class: XC\ATD\Core\API\APIService
    arguments:
      $httpClient: '@xc.atd.symfony.client'
      $authService: '@xc.atd.auth_service'
      $communicationLogger: '@xc.atd.communication_logger'
      $tries: '%atd.retries_api_service_count%'

  XC\ATD\Core\API\HttpClientFactory: ~

  xc.atd.symfony.client:
    class: Symfony\Component\HttpClient\HttpClient
    factory: ['@XC\ATD\Core\API\HttpClientFactory', 'createHttpClient']

  XC\ATD\Core\Data\Updater\ProductUpdater:
    class: XC\ATD\Core\Data\Updater\ProductUpdater
    public: true
    arguments:
      $categoryMapRepo: '@xc.atd.repository.category_map'
      $updateOptionsHelper: '@xc.atd.product.update.options.helper'
      $groupsStorage: '@xc.atd.core.helper.product_groups_storage'

  xc.atd.core.helper.product_groups_storage:
    public: true
    class: XC\AutoImportBase\Core\Helper\ProductGroupsStorage
    arguments:
      $metadataGateway: '@xc.atd.metadata_gateway'
      $productsRepo: '@xcart.repository.product.write'
    tags:
      - {name: kernel.event_listener, event: auto_import.products.batch.finished, method: flushGroups}

  XC\ATD\Core\Data\Updater\ShipmentStatusUpdater:
    class: XC\ATD\Core\Data\Updater\ShipmentStatusUpdater
    public: true
    arguments:
      $shippingStatusRepo: '@xc.atd.xcart.repository.order.status.shipping'

  XC\ATD\Core\Data\Updater\ShipmentTrackingNumbersUpdater:
    class: XC\ATD\Core\Data\Updater\ShipmentTrackingNumbersUpdater
    public: true

  XC\ATD\Core\Data\Helper\AtdShippingMethodsStorage:
    class: XC\ATD\Core\Data\Helper\AtdShippingMethodsStorage
    public: true

  XC\ATD\Core\Data\Adapter\Shipment\AtdShipmentConverter: ~

  XC\ATD\Core\Data\Adapter\Shipment\IShipmentAdapter:
    class: XC\ATD\Core\Data\Adapter\Shipment\AtdShipmentAdapter
    arguments:
      $logger: '@xc.atd.logger'

  XC\ATD\Logic\ShipmentCandidates\AtdShipmentsCandidatesProvider:
    public: true
    arguments:
      $metadataGateway: '@xc.atd.metadata_gateway'
    tags:
      - {name: 'xc.split_shipment.shipment_candidate_provider', priority: 1700}

  XC\ATD\Core\Creator\AtdOrderPlacer:
    class: XC\ATD\Core\Creator\AtdOrderPlacer
    public: true
    arguments:
      $logger: '@xc.atd.logger'
      $shippingMethodRepo: '@xc.atd.xcart.repository.shipping.method'
      $shippingStatusRepo: '@xc.atd.xcart.repository.order.status.shipping'

  XC\ATD\Core\Creator\AtdOrderPreviewer:
    class: XC\ATD\Core\Creator\AtdOrderPreviewer
    public: true
    arguments:
      $logger: '@xc.atd.logger'

  XC\ATD\Core\EventListener\AdminConstraintsFailedListener:
    arguments:
      $topMessageScheduler: '@xc.atd.top_message_scheduler'
    tags:
      - {name: kernel.event_listener, event: auto_import.block.import.constraints.failed, method: onConstraintFailed}

  XC\ATD\Core\Task\AtdOrderDetailsTask:
    tags:
      - {name: kernel.event_listener, event: xcart.cronjob, method: handleTask}

  XC\ATD\Core\API\LocationGateway\DataBuilder\LocationDataBuilder: ~

  XC\ATD\Core\API\LocationGateway\LocationGateway:
    class: XC\ATD\Core\API\LocationGateway\LocationGatewayImplementation
    public: true
    arguments:
      $apiService: '@xc.atd.api_service'
      $configuration: '@XC\ATD\Core\Configuration\Configuration'
      $locationDataBuilder: '@XC\ATD\Core\API\LocationGateway\DataBuilder\LocationDataBuilder'

  xc.atd.pull_locations:
    class: XC\AutoImportBase\Core\Command\Pull\PullLocations
    tags: [{name: xc.autoimportbase.pull_locations}]
    public: true
    arguments:
      $integrationName: '%atd.integration_name%'
      $logger: '@xc.atd.logger'
      $locationProvider: '@xc.atd.location_provider'

  xc.atd.location_provider:
    class: XC\ATD\Core\Provider\LocationProvider

  XC\ATD\Core\API\VehicleAPIGateway\IVehicleFitmentsAPIGateway:
    public: true
    class: XC\ATD\Core\API\VehicleAPIGateway\VehiclesAPIGatewayImplementation
    arguments:
      $apiService: '@xc.atd.api_service'
      $configuration: '@XC\ATD\Core\Configuration\Configuration'
      $vehicleDataBuilder: '@XC\ATD\Core\API\VehicleAPIGateway\DataBuilder\VehicleDataBuilder'
      $vehicleTrimOptionsDataBuilder: '@XC\ATD\Core\API\VehicleAPIGateway\DataBuilder\VehicleTrimOptionsDataBuilder'
      $vehicleInstallationSpecsDataBuilder: '@XC\ATD\Core\API\VehicleAPIGateway\DataBuilder\VehicleInstallationSpecsDataBuilder'

  XC\ATD\Core\API\VehicleAPIGateway\CachedInstallationSpecsDecorator:
    decorates: XC\ATD\Core\API\VehicleAPIGateway\IVehicleFitmentsAPIGateway
    class: XC\ATD\Core\API\VehicleAPIGateway\CachedInstallationSpecsDecorator
    arguments:
      $gateway: '@.inner'
      $cacheLifeTime: '%atd.cache_installation_spec_life_time_in_secs%'

  xc.atd.repository.vehicle_attribute_group:
    class: XC\WheelTireFitment\Model\Repo\VehicleAttributeGroup
    public: true
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - XC\WheelTireFitment\Model\VehicleAttributeGroup

  xc.atd.repository.vehicle_attribute_value:
    class: XC\WheelTireFitment\Model\Repo\VehicleAttributeValue
    public: true
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - XC\WheelTireFitment\Model\VehicleAttributeValue

  xc.atd.vehicle_attribute_group_helper:
    class: XC\AutoImportBase\Core\Data\Helper\VehicleAttributeGroupHelper
    arguments:
      $knownEntityHelper: '@XC\AutoImportBase\Core\Data\Helper\KnownEntityHelper'
      $vehicleAttributeGroupRepo: '@xc.atd.repository.vehicle_attribute_group'

  xc.atd.vehicle_attribute_value_helper:
    class: XC\AutoImportBase\Core\Data\Helper\VehicleAttributeValueHelper
    arguments:
      $knownEntityHelper: '@XC\AutoImportBase\Core\Data\Helper\KnownEntityHelper'
      $vehicleAttributeValueRepo: '@xc.atd.repository.vehicle_attribute_value'

  XC\ATD\Core\Provider\VehicleAttributeDataProvider:
    class: XC\ATD\Core\Provider\VehicleAttributeDataProvider
    public: true
    arguments:
      $configuration: '@XC\ATD\Core\Configuration\Configuration'
      $gateway: '@XC\ATD\Core\API\VehicleAPIGateway\IVehicleFitmentsAPIGateway'

  XC\ATD\Core\Provider\VehicleAttributesDataBuilder:
    class: XC\ATD\Core\Provider\VehicleAttributesDataBuilder
    public: true
    arguments:
      $attributeDataProvider: '@XC\ATD\Core\Provider\VehicleAttributeDataProvider'

  XC\ATD\Core\Data\Updater\VehicleAttributeUpdater:
    public: true
    class: XC\ATD\Core\Data\Updater\VehicleAttributeUpdater
    arguments:
      $vehicleAttributeGroupHelper: '@xc.atd.vehicle_attribute_group_helper'
      $vehicleAttributeValueHelper: '@xc.atd.vehicle_attribute_value_helper'
      $vehicleAttributesDataBuilder: '@XC\ATD\Core\Provider\VehicleAttributesDataBuilder'


framework:
  messenger:
    transports:
      async_atd_commands:
        dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        serializer: XCart\Messenger\Serializer
        options:
          queue_name: atd
      async_atd_vehicles_commands:
        dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        serializer: XCart\Messenger\Serializer
        options:
          queue_name: atd_vehicles
      async_atd_images_commands:
        dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        serializer: XCart\Messenger\Serializer
        options:
          queue_name: atd_images

    routing:
      'XC\ATD\Messenger\Message\ExecuteCommand': async_atd_commands
      'XC\ATD\Messenger\Message\ExecuteCommonVehiclesCommand': async_atd_vehicles_commands
      'XC\ATD\Messenger\Message\ExecuteImagesCommand': async_atd_images_commands

x_cart:
  transports_data:
    async_atd_commands:
      moduleId: XC-ATD
      description: 'Importing ATD brands, products, categories.'
    async_atd_vehicles_commands:
      moduleId: XC-ATD
      description: 'Importing vehicles with Wheel/Tire options.'
    async_atd_images_commands:
      moduleId: XC-ATD
      description: 'Downloading images.'
