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

x_cart:
  clean_urls:
    formats:
      # Brand Clean URL’s format
      # possible values:
      # domain/goalbrand
      # domain/goalbrand.html
      #
      # Changing this setting will not affect existing url's
      # and requires to re-deploy your store
      brand: 'domain/goalbrand'

dto_generator:
  entities:
    api:
      XCart\API\Entity\Storefront\Brand\Compact:
        name: Brand Compact
        logicEntity: XCart\Logic\Entity\Storefront\Brand
        path: /storefront/brands/compact
        register_get_one: true
        register_get_collection: true
        filters:
          - className: XCart\Bundle\APIPlatformBridgeBundle\Filter\StringFilter
            properties: [firstLetter, substring]
        fields:
          name:
            type: string
          cleanUrl:
            type: string
          logo:
            type: XCart\API\Entity\Storefront\Image
            nullable: true

      XCart\API\Entity\Storefront\Brand\Detailed:
        name: Brand Detailed
        logicEntity: XCart\Logic\Entity\Storefront\Brand
        path: /storefront/brands/detailed
        register_get_one: true
        itemOperations:
          getByCleanURL:
            method: GET
            path: /storefront/brands/detailed/by_clean_url/{clean_url}
            requirements:
              clean_url: '\S+'
            identifiers: [clean_url]
            openapi_context:
              summary: 'Retrieve a brand by clean url'
        fields:
          name:
            type: string
          cleanUrl:
            type: string
          logo:
            type: XCart\API\Entity\Storefront\Image
            nullable: true
          description:
            type: string
          metaTags:
            type: string
          metaDescription:
            type: string
          metaTitle:
            type: string

      XCart\API\Entity\Storefront\Product\Compact:
        fields:
          brandName:
            type: string
            nullable: true

      XCart\API\Entity\Storefront\Product\Detailed:
        fields:
          brand:
            type: XCart\API\Entity\Storefront\Brand
            nullable: true

    logic:
      XCart\Logic\Entity\Storefront\Brand:
        doctrineEntity: QSL\ShopByBrand\Model\Brand
        generate_get_one: true
        generate_get_collection: true
        use_doctrine_get_one: true
        use_doctrine_get_collection: true
        fields:
          name:
            type: string
          cleanUrl:
            type: string
          logo:
            type: XCart\Logic\Entity\Storefront\Image
            nullable: true
          description:
            type: string
          metaTags:
            type: string
          metaDescription:
            type: string
          metaTitle:
            type: string

      XCart\Logic\Entity\Storefront\Product:
        fields:
          brandName:
            type: string
          brand:
            type: XCart\Logic\Entity\Storefront\Brand

    dto:
      XCart\API\Entity\Storefront\Brand:
        fields:
          name:
            type: string
          cleanUrl:
            type: string
          logo:
            type: XCart\API\Entity\Storefront\Image
            nullable: true

      XCart\Logic\Action\Storefront\Brand\GetList\DTO\Request\Filter:
        type: logic_request_get_list_filter
        fields:
          enabled:
            type: BooleanValue
            nullable: true
          substring:
            type: StringValue
            nullable: true
          firstLetter:
            type: StringValue
            nullable: true

      XCart\DTO\Doctrine\Storefront\Brand\Filter:
        type: doctrine_entity_filter
        fields:
          enabled:
            type: BooleanValue
            nullable: true
          substring:
            type: StringValue
            nullable: true
          firstLetter:
            type: StringValue
            nullable: true

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

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

  transformers:
    - from: QSL\ShopByBrand\Model\Brand
      to: XCart\Logic\Entity\Storefront\Brand
    - from: XCart\Logic\Entity\Storefront\Brand
      to: QSL\ShopByBrand\Model\Brand

services:
  _defaults:
    autowire: true
    autoconfigure: true

  # API
  QSL\ShopByBrand\API\OpenApiTagsRepositoryDecorator:
    decorates: XLite\API\OpenApiTagsRepository

  # data source
  xcart.data_source.brand.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.brand.read'
      $collectionClassName: 'QSL\ShopByBrand\Entity\BrandCollection'
      $queryBuilderFilterEnricher: '@xcart.data_source.brand.read.query_builder_filter.enricher'

  xcart.repository.brand.read:
    class: QSL\ShopByBrand\Model\Repo\Brand
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    calls:
      - [setQueryBuilderFactory, ['@xcart.query_builder.factory.brand.read']]
    arguments:
      - QSL\ShopByBrand\Model\Brand

  xcart.query_builder.factory.brand.read:
    class: XCart\Bundle\DoctrineBridgeBundle\QueryBuilder\Factory\QueryBuilderFactory
    arguments:
      $entityManager: '@doctrine.orm.entity_manager'
      $className: XCart\Bundle\DoctrineBridgeBundle\QueryBuilder\CommonQueryBuilder

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

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

  xcart.data_source.brand.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.brand.read.query_builder.enricher.field_name.assembler:
    class: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Assembler\FieldNameAssembler

  xcart.data_source.brand.read.query_builder_filter.enricher.filter_applier.resolver.decorator.substring:
    class: QSL\ShopByBrand\Logic\Action\Storefront\Brand\GetList\Resolver\SubstringFilterApplierResolverDecorator
    decorates: xcart.data_source.brand.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'

  xcart.data_source.brand.read.query_builder_filter.enricher.filter_applier.resolver.decorator.firstletter:
    class: QSL\ShopByBrand\Logic\Action\Storefront\Brand\GetList\Resolver\FirstLetterFilterApplierResolverDecorator
    decorates: xcart.data_source.brand.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'

  xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver.decorator.brand:
    class: QSL\ShopByBrand\Logic\Action\Storefront\Product\GetList\Resolver\BrandFilterApplierResolverDecorator
    decorates: xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'
      $brandRepository: '@xcart.repository.brand.read'

  # Transformers
  QSL\ShopByBrand\Transformer\QSL\ShopByBrand\Model\Brand\Logic\Entity\Storefront\BrandDecorator:
    decorates: 'XCart\Transformer\QSL\ShopByBrand\Model\Brand\Logic\Entity\Storefront\Brand'
    arguments:
      $inner: '@.inner'
      $factory: '@XCart\Factory\Logic\Entity\Storefront\Brand'

  QSL\ShopByBrand\Transformer\XLite\Model\Product\Logic\Entity\Storefront\ProductDecorator:
    decorates: XCart\Transformer\XLite\Model\Product\Logic\Entity\Storefront\Product
    arguments:
      $brandTransformer: '@QSL\ShopByBrand\Transformer\QSL\ShopByBrand\Model\Brand\Logic\Entity\Storefront\BrandDecorator'

  # get one by id (compact)
  xcart.api.storefront.brand.compact.data_provider.item.get_one_by_id:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\Brand\Compact]
      $action: '@xcart.logic.storefront.brand.get_one_by_id.action'
      $requestAssembler: '@xcart.api.storefront.brand.compact.data_provider.item.request.assembler'
      $responseAssembler: '@xcart.api.storefront.brand.compact.data_provider.item.response.assembler'
      $operationNames: [get]

  xcart.logic.storefront.brand.get_one_by_id.action:
    class: QSL\ShopByBrand\Logic\Action\Storefront\Brand\GetOne\Action
    arguments:
      $readRepository: '@xcart.repository.brand.read'
      $entityIdAssembler: '@xcart.logic.storefront.brand.get_one.action.entity_id.assembler'
      $responseAssembler: '@xcart.logic.storefront.brand.get_one.response.assembler'
    tags:
      - {name: xcart.logic.action, request: XCart\Logic\Action\Storefront\Brand\GetOne\DTO\Request, response: XCart\Logic\Action\Storefront\Brand\GetOne\DTO\Response}

  # get one by id (detailed)
  xcart.api.storefront.brand.detailed.data_provider.item.get_one_by_id:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\Brand\Detailed]
      $action: '@xcart.logic.storefront.brand.get_one_by_id.action'
      $requestAssembler: '@xcart.api.storefront.brand.detailed.data_provider.item.request.assembler'
      $responseAssembler: '@xcart.api.storefront.brand.detailed.data_provider.item.response.assembler'
      $operationNames: [get]

  # get one by clean url
  xcart.api.storefront.brand.detailed.data_provider.item.get_by_clean_url:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\Brand\Detailed]
      $action: '@xcart.logic.storefront.brand.get_one_by_clean_url.action'
      $requestAssembler: '@xcart.api.storefront.brand.detailed.data_provider.item.request.assembler.get_one_by_clean_url'
      $responseAssembler: '@xcart.api.storefront.brand.detailed.data_provider.item.response.assembler'
      $operationNames: [getByCleanURL]

  xcart.api.storefront.brand.detailed.data_provider.item.request.assembler.get_one_by_clean_url:
    class: QSL\ShopByBrand\API\Endpoint\Storefront\Brand\Detailed\GetOneByCleanURL\Assembler\RequestAssembler
    arguments:
      $requestFactory: '@QSL\ShopByBrand\Factory\Logic\Action\Storefront\Brand\Detailed\GetOneByCleanURL\DTO\RequestInterface'

  QSL\ShopByBrand\Factory\Logic\Action\Storefront\Brand\Detailed\GetOneByCleanURL\DTO\RequestInterface: '@QSL\ShopByBrand\Factory\Logic\Action\Storefront\Brand\Detailed\GetOneByCleanURL\DTO\Request'
  QSL\ShopByBrand\Factory\Logic\Action\Storefront\Brand\Detailed\GetOneByCleanURL\DTO\Request:
    class: QSL\ShopByBrand\Factory\Logic\Action\Storefront\Brand\Detailed\GetOneByCleanURL\DTO\Request

  xcart.logic.storefront.brand.get_one_by_clean_url.action:
    class: QSL\ShopByBrand\Logic\Action\Storefront\Brand\GetOne\Action
    arguments:
      $readRepository: '@xcart.repository.brand.read'
      $entityIdAssembler: '@xcart.logic.storefront.brand.get_one_by_clean_url.entity_id.assembler'
      $responseAssembler: '@xcart.logic.storefront.brand.get_one.response.assembler'
    tags:
      - {name: xcart.logic.action, request: QSL\ShopByBrand\Logic\Action\Storefront\Brand\Detailed\GetOneByCleanURL\DTO\Request, response: XCart\Logic\Action\Storefront\Brand\Detailed\GetOneByCleanURL\DTO\Response}

  xcart.logic.storefront.brand.get_one_by_clean_url.entity_id.assembler:
    class: QSL\ShopByBrand\Logic\Action\Storefront\Brand\Detailed\GetOneByCleanURL\Assembler\EntityIdAssembler
    arguments:
      $cleanURLRepository: '@xcart.repository.clean_url'

  # get list
  xcart.doctrine.storefront.brand.criteria.assembler.decorator.enabled:
    class: QSL\ShopByBrand\Logic\Action\Storefront\Brand\GetList\Assembler\Criteria\FindListCriteriaAssemblerDecorator
    decorates: xcart.doctrine.storefront.brand.criteria.assembler
    decoration_priority: 10
    arguments:
      '$inner': '@.inner'
