#
# 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:
  mapping:
    paths:
      - '%kernel.project_dir%/var/run/classes/CDev/FeaturedProducts/Model'

dto_generator:
  entities:
    api:
      XCart\API\Entity\Storefront\Product\Compact:
        collectionOperations:
          getFeaturedProducts:
            method: GET
            path: /storefront/products/compact/featured/home_page
            openapi_context:
              summary: 'Retrieve a list of featured products for the home page'
          getFeaturedProductsFromCategory:
            method: GET
            path: /storefront/products/compact/featured/{category_id}
            identifiers: [category_id]
            openapi_context:
              summary: 'Retrieve a list of featured products for the category'
              parameters:
                - name: category_id
                  in: path
                  required: true
                  schema:
                    type: integer
                    minimum: 1

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

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

services:
  _defaults:
    autowire: true
    autoconfigure: true

  CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\Transformer\InputTransformerInterface: '@CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\Transformer\InputTransformer'
  CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\Transformer\InputTransformer: ~
  CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\Transformer\OutputTransformerInterface: '@CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\Transformer\OutputTransformer'
  CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\Transformer\OutputTransformer: ~

  CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\DataProvider\FeaturedDataProvider: ~

  CDev\FeaturedProducts\Controller\API\FeaturedProduct\DeleteCategoryFeatured:
    tags: ['controller.service_arguments']

  CDev\FeaturedProducts\Controller\API\FeaturedProduct\DeleteFrontPageFeatured:
    tags: ['controller.service_arguments']

  CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\SubIdentifierExtractor\SubIdentifierExtractor:
    tags: [!php/const XCart\Framework\ApiPlatform\Core\Api\SubIdentifierExtractor\SubIdentifierExtractorInterface::SUB_IDENTIFIER_EXTRACTOR_TAG]

  CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\SubExtension\SubExtension:
    tags: [!php/const XLite\API\Extension\ItemSubExtension\ItemSubExtensionInterface::ITEM_SUB_EXTENSION_TAG]

  CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\SubIriConverter\SubIriConverter:
    tags: [!php/const XCart\Framework\ApiPlatform\Core\Bridge\Symfony\Routing\SubIriConverter\SubIriFromItemConverterInterface::SUB_IRI_FROM_ITEM_CONVERTER_TAG]

  CDev\FeaturedProducts\API\OpenApiTagsRepositoryDecorator:
    decorates: XLite\API\OpenApiTagsRepository

  # getFeaturedProducts and getFeaturedProductsFromCategory operations
  xcart.api.storefront.product.compact.data_provider.collection.get_featured_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.featured_products.product.compact.data_provider.collection.request.assembler.get_featured_products'
      $responseAssembler: '@xcart.api.storefront.product.compact.data_provider.collection.response.assembler'
      $operationNames: ['getFeaturedProducts', 'getFeaturedProductsFromCategory']

  xcart.api.storefront.xc.featured_products.product.compact.data_provider.collection.request.assembler.get_featured_products:
    class: CDev\FeaturedProducts\API\Endpoint\Storefront\Product\Compact\GetFeaturedProducts\Assembler\RequestAssembler
    arguments:
      $internal: '@xcart.api.storefront.product.compact.data_provider.collection.request.assembler'

  xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver.decorator.featuredProducts:
    class: CDev\FeaturedProducts\Logic\Action\Storefront\Product\GetList\Resolver\FeaturedProductsFilterApplierResolverDecorator
    decorates: xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'
