#
# 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:
      # Vendor Clean URL’s format
      # possible values:
      #  domain/goalvendor
      #  domain/goalvendor.html
      #
      # Changing this setting will not affect existing url's
      # and requires to re-deploy your store
      vendor: 'domain/goalvendor'

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

dto_generator:
  entities:
    api:
      XCart\API\Entity\Storefront\VendorCompact:
        name: Vendor Compact
        logicEntity: XCart\Logic\Entity\Storefront\Vendor
        path: /storefront/vendors/compact
        register_get_one: true
        register_get_collection: true
        fields:
          vendorName:
            type: string
          cleanUrl:
            type: string
          rating:
            type: float
            nullable: true
      XCart\API\Entity\Storefront\VendorDetailed:
        name: Vendor Detailed
        logicEntity: XCart\Logic\Entity\Storefront\Vendor
        path: /storefront/vendors/detailed
        register_get_one: true
        register_get_collection: true
        fields:
          vendorName:
            type: string
          cleanUrl:
            type: string
          image:
            type: XCart\API\Entity\Storefront\Image
          location:
            type: string
          description:
            type: string
          rating:
            type: float
            nullable: true
      XCart\API\Entity\Storefront\Product\Compact:
        fields:
          vendorName:
            type: string
            nullable: true
      XCart\API\Entity\Storefront\Product\Detailed:
        fields:
          vendor:
            type: XCart\API\Entity\Storefront\VendorCompact
            nullable: true
    logic:
      XCart\Logic\Entity\Storefront\Vendor:
        doctrineEntity: XC\MultiVendor\Model\Vendor
        generate_get_one: true
        generate_get_collection: true
        use_doctrine_get_one: true
        use_doctrine_get_collection: true
        fields:
          vendorName:
            type: string
          cleanUrl:
            type: string
          image:
            type: XCart\Logic\Entity\Storefront\Image
          location:
            type: string
          description:
            type: string
          rating:
            type: float
            nullable: true
      XCart\Logic\Entity\Storefront\Product:
        fields:
          vendor:
            type: XCart\Logic\Entity\Storefront\Vendor
            nullable: true
          vendorName:
            type: string
            nullable: true
    dto:
      XCart\Logic\Action\Storefront\Product\GetList\DTO\Request\Filter:
        type: logic_request_get_list_filter
        fields:
          vendor:
            type: IntegerValue
            nullable: true
      XCart\DTO\Doctrine\Storefront\Product\Filter:
        type: doctrine_entity_filter
        fields:
          vendor:
            type: IntegerValue
            nullable: true
          vendorProfileStatus:
            type: StringValue
            nullable: true
      XCart\Logic\Action\Storefront\Category\GetList\DTO\Request\Filter:
        type: logic_request_get_list_filter
        fields:
          vendor:
            type: IntegerValue
            nullable: true
      XCart\DTO\Doctrine\Storefront\Category\Filter:
        type: doctrine_entity_filter
        fields:
          vendor:
            type: IntegerValue
            nullable: true
      XCart\DTO\Doctrine\Storefront\Vendor\Filter:
        type: doctrine_entity_filter
        fields:
          vendorProfileStatus:
            type: StringValue
            nullable: true
  transformers:
    - from: XC\MultiVendor\Model\Vendor
      to: XCart\Logic\Entity\Storefront\Vendor
    - from: XCart\Logic\Entity\Storefront\Vendor
      to: XCart\API\Entity\Storefront\VendorCompact
    - from: XCart\Logic\Entity\Storefront\Vendor
      to: XCart\API\Entity\Storefront\VendorDetailed

services:
  _defaults:
    autowire: true
    autoconfigure: true

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

  XC\MultiVendor\API\Endpoint\Profile\Builder\AdminCountQueryBuilderDecorator:
    class: XC\MultiVendor\API\Endpoint\Profile\Builder\AdminCountQueryBuilderDecorator
    decorates: XLite\API\Endpoint\Profile\Builder\AdminCountQueryBuilder

  xcart.repository.xc.multi_vendor.vendor:
    class: XC\MultiVendor\Model\Repo\Vendor
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - XC\MultiVendor\Model\Vendor

  xcart.repository.xc.multi_vendor.profile_transaction:
    class: XC\MultiVendor\Model\Repo\ProfileTransaction
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - XC\MultiVendor\Model\ProfileTransaction

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

  # /vendors
  XC\MultiVendor\API\Endpoint\Vendor\Transformer\OutputTransformerInterface: '@XC\MultiVendor\API\Endpoint\Vendor\Transformer\OutputTransformer'
  XC\MultiVendor\API\Endpoint\Vendor\Transformer\OutputTransformer: ~
  XC\MultiVendor\API\Endpoint\Vendor\Transformer\InputTransformerInterface: '@XC\MultiVendor\API\Endpoint\Vendor\Transformer\InputTransformer'
  XC\MultiVendor\API\Endpoint\Vendor\Transformer\InputTransformer: ~

  XC\MultiVendor\API\Endpoint\Vendor\DataProvider\ItemDataProvider:
    arguments:
      $inner: '@api_platform.doctrine.orm.default.item_data_provider'

  xcart.api.xc.multi_vendor.vendor.controller:
    class: XC\MultiVendor\Controller\API\Vendor\Post
    public: true

  xcart.api.xc.multi_vendor.vendor.sub_identifier_extractor:
    class: XC\MultiVendor\API\Endpoint\Vendor\SubIdentifierExtractor\SubIdentifierExtractor
    tags: [!php/const XCart\Framework\ApiPlatform\Core\Api\SubIdentifierExtractor\SubIdentifierExtractorInterface::SUB_IDENTIFIER_EXTRACTOR_TAG]

  # /vendors/{vendor_id}/transactions
  XC\MultiVendor\API\Endpoint\VendorTransaction\Transformer\OutputTransformerInterface: '@XC\MultiVendor\API\Endpoint\VendorTransaction\Transformer\OutputTransformer'
  XC\MultiVendor\API\Endpoint\VendorTransaction\Transformer\OutputTransformer: ~

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

  XC\MultiVendor\API\Endpoint\VendorTransaction\DataProvider\CollectionDataProvider:
    arguments:
      $inner: '@api_platform.doctrine.orm.default.collection_data_provider'
      $repository: '@xcart.repository.xc.multi_vendor.vendor'

  XC\MultiVendor\API\Endpoint\VendorTransaction\DataProvider\ItemDataProvider:
    arguments:
      $inner: '@api_platform.doctrine.orm.default.item_data_provider'
      $repository: '@xcart.repository.xc.multi_vendor.vendor'

  xcart.api.xc.multi_vendor.vendor_transaction.sub_extension:
    class: XC\MultiVendor\API\Endpoint\VendorTransaction\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]

  # /orders
  xcart.api.xc.multi_vendor.order.order_based_sub_extension:
    class: XC\MultiVendor\API\Endpoint\Order\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]

  XC\MultiVendor\EntityCallback\VendorRatingCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XC\MultiVendor\Model\VendorRating}

  XC\MultiVendor\EntityCallback\CompanyFieldCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XC\MultiVendor\Model\CompanyField}
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XC\MultiVendor\Model\CompanyField}

  XC\MultiVendor\EntityCallback\OrderCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: postPersist, entity: XLite\Model\Order}
      - {name: doctrine.orm.entity_listener, event: postUpdate, entity: XLite\Model\Order}

  # repositories
  xcart.repository.vendor.read:
    class: XC\MultiVendor\Model\Repo\Vendor
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    calls:
      - [setQueryBuilderFactory, ['@xcart.query_builder.factory.vendor.read']]
    arguments:
      - XC\MultiVendor\Model\Vendor

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

  # data source
  xcart.data_source.vendor.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.vendor.read'
      $collectionClassName: XC\MultiVendor\Entity\VendorCollection

  # transformer decorator
  XC\MultiVendor\Transformer\XC\MultiVendor\Model\Vendor\Logic\Entity\Storefront\VendorDecorator:
    decorates: XCart\Transformer\XC\MultiVendor\Model\Vendor\Logic\Entity\Storefront\Vendor
    arguments:
      $inner: '@.inner'

  XC\MultiVendor\Transformer\XLite\Model\Product\Logic\Entity\Storefront\ProductDecorator:
    decorates: XCart\Transformer\XLite\Model\Product\Logic\Entity\Storefront\Product
    arguments:
      $inner: '@.inner'

  # actions
  xcart.api.storefront.vendorcompact.data_provider.item.get_one_by_id:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\VendorCompact]
      $action: '@xcart.logic.storefront.vendor.get_one_by_id.action'
      $requestAssembler: '@xcart.api.storefront.vendorcompact.data_provider.item.request.assembler'
      $responseAssembler: '@xcart.api.storefront.vendorcompact.data_provider.item.response.assembler'
      $operationNames: [get]

  xcart.api.storefront.vendordetailed.data_provider.item.get_one_by_id:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\VendorDetailed]
      $action: '@xcart.logic.storefront.vendor.get_one_by_id.action'
      $requestAssembler: '@xcart.api.storefront.vendordetailed.data_provider.item.request.assembler'
      $responseAssembler: '@xcart.api.storefront.vendordetailed.data_provider.item.response.assembler'
      $operationNames: [get]

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

  # assemblers
  xcart.doctrine.storefront.vendorproduct.criteria.assembler.decorator.type:
    class: XC\MultiVendor\Action\Storefront\Product\Assembler\Criteria\FindListCriteriaAssemblerDecorator
    decorates: xcart.doctrine.storefront.product.criteria.assembler
    decoration_priority: 10
    arguments:
      $inner: '@.inner'

  xcart.data_source.vendor.read.query_builder_filter.enricher.filter_applier.resolver.decorator.vendor:
    class: XC\MultiVendor\Logic\Action\Storefront\Product\GetList\Resolver\VendorFilterApplierResolverDecorator
    decorates: xcart.data_source.product.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'
      $vendorRepository: '@xcart.repository.vendor.read'

  xcart.logic.storefront.product.get_one_by_id.assembler.query_builder.decorator.vendor:
    class: XC\MultiVendor\Logic\Action\Storefront\Product\GetOne\Assembler\QueryBuilder\FindOneQueryBuilderAssemblerDecorator
    decorates: xcart.logic.storefront.product.get_one_by_id.assembler.query_builder
    arguments:
      $inner: '@.inner'

  xcart.doctrine.storefront.vendorcategory.criteria.assembler.decorator.type:
    class: XC\MultiVendor\Action\Storefront\Category\Assembler\Criteria\FindListCriteriaAssemblerDecorator
    decorates: xcart.doctrine.storefront.category.criteria.assembler
    decoration_priority: 10
    arguments:
      $inner: '@.inner'

  xcart.data_source.vendorcategory.read.query_builder_filter.enricher.filter_applier.resolver.decorator.vendor:
    class: XC\MultiVendor\Logic\Action\Storefront\Category\GetList\Resolver\VendorFilterApplierResolverDecorator
    decorates: xcart.data_source.category.read.query_builder_filter.enricher.filter_applier.resolver
    arguments:
      $inner: '@.inner'
      $vendorRepository: '@xcart.repository.vendor.read'
      $categoryRepository: '@xcart.repository.category.read'

  xcart.doctrine.storefront.vendorvendor.criteria.assembler.decorator.type:
    class: XC\MultiVendor\Action\Storefront\Vendor\Assembler\Criteria\FindListCriteriaAssemblerDecorator
    decorates: xcart.doctrine.storefront.vendor.criteria.assembler
    decoration_priority: 10
    arguments:
      $inner: '@.inner'

  xcart.data_source.vendorvendor.read.query_builder_filter.enricher.filter_applier.resolver.decorator.vendor:
    class: XC\MultiVendor\Logic\Action\Storefront\Vendor\GetList\Resolver\VendorFilterApplierResolverDecorator
    decorates: XCart\Bundle\DoctrineBridgeBundle\Enricher\GetList\Filter\Resolver\FilterApplierResolver
    arguments:
      $inner: '@.inner'
