services:
  _defaults:
    autowire: true
    autoconfigure: true

  # category : read
  xcart.data_source.category.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.category.read'
      $collectionClassName: 'XCart\Entity\CategoryCollection'
      $queryBuilderFilterEnricher: '@xcart.data_source.category.read.query_builder_filter.enricher'

  xcart.data_source.category.read.query_builder_filter.enricher:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Filter\CommonFilterEnricher
    arguments:
      $filterListAssembler: '@xcart.data_source.category.read.query_builder_filter.enricher.filter_list.assembler'

  xcart.data_source.category.read.query_builder_filter.enricher.filter_list.assembler:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Filter\Assembler\FilterListAssembler
    arguments:
      $applierResolver: '@xcart.data_source.category.read.query_builder_filter.enricher.filter_applier.resolver'
      $fieldNameAssembler: '@xcart.data_source.category.read.query_builder_filter.enricher.field_name.assembler'

  xcart.data_source.category.read.query_builder_filter.enricher.filter_applier.resolver:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Filter\Resolver\FilterApplierResolver
    arguments:
      $appliers: '@xcart.bundle.doctrine_bridge_bundle.action.get_list.enricher.appliers'

  xcart.data_source.category.read.query_builder_filter.enricher.field_name.assembler:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Assembler\FieldNameAssembler

  xcart.data_source.category.read.query_builder_filter.enricher.filter_applier.resolver.decorator.membership:
    class: XCart\Logic\Action\Storefront\Common\GetList\Resolver\MembershipFilterApplierResolverDecorator
    decorates: xcart.data_source.category.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'

  # category : write
  xcart.data_source.category.write:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineWriteDataSource
    arguments:
      $repository: '@xcart.repository.category.write'
      $collectionClassName: 'XCart\Entity\CategoryCollection'

  # Product : read
  xcart.data_source.product.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.product.read'
      $collectionClassName: 'XCart\Entity\ProductCollection'
      $queryBuilderFilterEnricher: '@xcart.data_source.product.read.query_builder_filter.enricher'
      $queryBuilderOrderRuleEnricher: '@xcart.data_source.product.read.query_builder_order_rule.enricher'

  xcart.data_source.product.read.query_builder_order_rule.enricher:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\OrderRule\CommonOrderRuleEnricher
    arguments:
      $fieldNameAssembler: '@xcart.data_source.product.read.query_builder.enricher.field_name.assembler'

  xcart.data_source.product.read.query_builder_order_rule.enricher.decorator.price:
    class: XCart\Logic\Action\Storefront\Product\GetList\Enricher\OrderRule\PriceOrderRuleEnricherDecorator
    decorates: xcart.data_source.product.read.query_builder_order_rule.enricher
    arguments:
      $inner: '@.inner'

  xcart.data_source.product.read.query_builder_filter.enricher:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Filter\CommonFilterEnricher
    arguments:
      $filterListAssembler: '@xcart.data_source.product.read.query_builder_filter.enricher.filter_list.assembler'

  xcart.data_source.product.read.query_builder_filter.enricher.filter_list.assembler:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Filter\Assembler\FilterListAssembler
    arguments:
      $applierResolver: '@xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver'
      $fieldNameAssembler: '@xcart.data_source.product.read.query_builder.enricher.field_name.assembler'

  xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Filter\Resolver\FilterApplierResolver
    arguments:
      $appliers: '@xcart.bundle.doctrine_bridge_bundle.action.get_list.enricher.appliers'

  xcart.data_source.product.read.query_builder.enricher.field_name.assembler:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Assembler\FieldNameAssembler

  xcart.data_source.product.read.query_builder.enricher.field_name.assembler.decorator.id:
    class: XCart\Logic\Action\Storefront\Product\GetList\Assembler\IdFieldNameAssemblerDecorator
    decorates: xcart.data_source.product.read.query_builder.enricher.field_name.assembler
    decoration_priority: 10
    arguments:
      $inner: '@.inner'

  xcart.data_source.product.read.query_builder.enricher.field_name.assembler.decorator.name:
    class: XCart\Logic\Action\Storefront\Product\GetList\Assembler\NameFieldNameAssemblerDecorator
    decorates: xcart.data_source.product.read.query_builder.enricher.field_name.assembler
    decoration_priority: 20
    arguments:
      $inner: '@.inner'

  xcart.data_source.product.read.query_builder.enricher.field_name.assembler.decorator.products:
    class: XCart\Logic\Action\Storefront\Product\GetList\Assembler\ProductsFieldNameAssemblerDecorator
    decorates: xcart.data_source.product.read.query_builder.enricher.field_name.assembler
    decoration_priority: 30
    arguments:
      $inner: '@.inner'

  xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver.decorator.substring:
    class: XCart\Logic\Action\Storefront\Product\GetList\Resolver\SubstringFilterApplierResolverDecorator
    decorates: xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'
      $getLinkedTables: '@XCart\Operation\Service\DataSource\Product\Applier\SubstringApplier\GetLinkedTablesInterface'
      $getSubstringSearchFields: '@XCart\Operation\Service\DataSource\Product\Applier\SubstringApplier\GetSubstringSearchFieldsInterface'

  xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver.decorator.categories:
    class: XCart\Logic\Action\Storefront\Product\GetList\Resolver\CategoriesFilterApplierResolverDecorator
    decorates: xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'

  xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver.decorator.outOfStock:
    class: XCart\Logic\Action\Storefront\Product\GetList\Resolver\OutOfStockFilterApplierResolverDecorator
    decorates: xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'

  xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver.decorator.membership:
    class: XCart\Logic\Action\Storefront\Common\GetList\Resolver\MembershipFilterApplierResolverDecorator
    decorates: xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'

  # Product : write
  xcart.data_source.product.write:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineWriteDataSource
    arguments:
      $repository: '@xcart.repository.product.write'
      $collectionClassName: 'XCart\Entity\ProductCollection'

  # profile
  xcart.data_source.profile.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.profile.read'
      $collectionClassName: 'XCart\Entity\ProfileCollection'

  xcart.data_source.payment.transaction.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.payment.transaction.read'
      $collectionClassName: XCart\Entity\Payment\TransactionCollection

  # @todo: it is temporary solution, read data source (action) need to use findOneBy instead of findOne (ECOM-3177)
  XCart\DataSource\Payment\TransactionRead:
    decorates: xcart.data_source.payment.transaction.read
    arguments:
      $inner: '@.inner'
      $repository: '@xcart.repository.payment.transaction.read'

  # cart
  xcart.data_source.cart.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.cart.read'
      $collectionClassName: 'XCart\Entity\CartCollection'

  xcart.data_source.cart.write:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineWriteDataSource
    arguments:
      $repository: '@xcart.repository.cart.write'
      $collectionClassName: 'XCart\Entity\CartCollection'

  xcart.data_source.orderitem.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.orderitem.read'
      $collectionClassName: 'XCart\Entity\OrderItemCollection'

  # Address
  xcart.data_source.address.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.address.read'
      $collectionClassName: 'XCart\Entity\AddressCollection'

  # Address field
  xcart.data_source.addressfield.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.addressfield.read'
      $collectionClassName: 'XCart\Entity\AddressFieldCollection'

  # Config
  xcart.data_source.config.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.config.read'
      $collectionClassName: 'XCart\Entity\ConfigCollection'

  # Country
  xcart.data_source.country.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.country.read'
      $collectionClassName: 'XCart\Entity\CountryCollection'
      $queryBuilderOrderRuleEnricher: '@xcart.data_source.country.read.query_builder_order_rule.enricher'

  xcart.data_source.country.read.query_builder_order_rule.enricher:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\OrderRule\CommonOrderRuleEnricher
    arguments:
      $fieldNameAssembler: '@xcart.data_source.country.read.query_builder.enricher.field_name.assembler'

  xcart.data_source.country.read.query_builder.enricher.field_name.assembler:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Assembler\FieldNameAssembler

  xcart.data_source.country.read.query_builder_order_rule.enricher.decorator.name:
    class: XCart\Logic\Action\Storefront\Country\GetList\Enricher\OrderRule\NameOrderRuleEnricherDecorator
    decorates: xcart.data_source.country.read.query_builder_order_rule.enricher
    arguments:
      $inner: '@.inner'
