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

api_platform:
  resource_class_directories:
    - '%kernel.project_dir%/var/run/classes/XC/Upselling/Model'

dto_generator:
  entities:
    api:
      XCart\API\Entity\Storefront\Product\Compact:
        collectionOperations:
          getRelatedProducts:
            method: GET
            path: /storefront/products/compact/{product_id}/related
            identifiers: [product_id]
            openapi_context:
              summary: 'Retrieve a list of related products'
              parameters:
                - name: product_id
                  in: path
                  required: true
                  schema:
                    type: integer
                    minimum: 1

    dto:
      XCart\Logic\Action\Storefront\Product\GetList\DTO\Request\Filter:
        fields:
          relatedOwnerId:
            type: IntegerValue
            nullable: true

      XCart\DTO\Doctrine\Storefront\Product\Filter:
        fields:
          relatedOwnerId:
            type: IntegerValue
            nullable: true

services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: true

  XC_Upselling.listener.unique_constraints:
    class: XC\Upselling\Core\EventListener\UniqueConstraintsEventListener
    tags:
      - { name: doctrine.event_listener, event: loadClassMetadata, method: loadClassMetadata }

  # /product/{product_id}/related_products
  XC\Upselling\API\Endpoint\ProductUpsellingProduct\Transformer\OutputTransformerInterface: '@XC\Upselling\API\Endpoint\ProductUpsellingProduct\Transformer\OutputTransformer'
  XC\Upselling\API\Endpoint\ProductUpsellingProduct\Transformer\OutputTransformer: ~
  XC\Upselling\API\Endpoint\ProductUpsellingProduct\Transformer\InputTransformerInterface: '@XC\Upselling\API\Endpoint\ProductUpsellingProduct\Transformer\InputTransformer'
  XC\Upselling\API\Endpoint\ProductUpsellingProduct\Transformer\InputTransformer: ~

  XC\Upselling\API\Endpoint\ProductUpsellingProduct\SubIriConverter\SubIriConverter:
    tags: [!php/const XCart\Framework\ApiPlatform\Core\Bridge\Symfony\Routing\SubIriConverter\SubIriFromItemConverterInterface::SUB_IRI_FROM_ITEM_CONVERTER_TAG]

  XC\Upselling\API\Endpoint\ProductUpsellingProduct\DataProvider\CollectionDataProvider:
    arguments:
      $inner: '@api_platform.doctrine.orm.default.collection_data_provider'
      $repository: '@xcart.repository.product'

  XC\Upselling\API\Endpoint\ProductUpsellingProduct\DataProvider\ItemDataProvider:
    arguments:
      $inner: '@api_platform.doctrine.orm.default.item_data_provider'
      $repository: '@xcart.repository.product'

  xcart.api.xc.upselling.product_upselling_product.controller:
    class: XC\Upselling\Controller\API\ProductUpsellingProduct\Post
    arguments:
      $repository: '@xcart.repository.product'

  XC\Upselling\API\OpenApiTagsRepositoryDecorator:
    decorates: XLite\API\OpenApiTagsRepository

  xcart.api.xc.upselling.product_upselling_product.sub_extension:
    class: XC\Upselling\API\Endpoint\ProductUpsellingProduct\SubExtension\SubExtension
    tags: [!php/const XLite\API\Extension\CollectionSubExtension\CollectionSubExtensionInterface::COLLECTION_SUB_EXTENSION_TAG, !php/const XLite\API\Extension\ItemSubExtension\ItemSubExtensionInterface::ITEM_SUB_EXTENSION_TAG]

  # getRelatedProducts operation
  xcart.api.storefront.product.compact.data_provider.collection.get_related_products:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Collection\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\Product\Compact]
      $action: '@xcart.logic.storefront.product.get_collection.action'
      $requestAssembler: '@xcart.api.storefront.xc.upselling.product.compact.data_provider.collection.request.assembler.get_related_products'
      $responseAssembler: '@xcart.api.storefront.product.compact.data_provider.collection.response.assembler'
      $operationNames: [getRelatedProducts]

  xcart.api.storefront.xc.upselling.product.compact.data_provider.collection.request.assembler.get_related_products:
    class: XC\Upselling\API\Endpoint\Storefront\Product\Compact\GetRelatedProducts\Assembler\RequestAssembler
    arguments:
      $internal: '@xcart.api.storefront.product.compact.data_provider.collection.request.assembler'

  xcart.data_source.xc.upselling.product.read.query_builder_filter.enricher.filter_applier.resolver.decorator.related_owner:
    class: XC\Upselling\Logic\Action\Storefront\Product\GetList\Resolver\RelatedOwnerFilterApplierResolverDecorator
    decorates: xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'
