#
# 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/CDev/PINCodes/Model'

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

  CDev\PINCodes\Core\EventListener:
    tags:
      - {name: kernel.event_listener, event: xcart.service.view-list.collect-mutation, method: onCollectViewListMutations}

  # /product/{product_id}/related_products
  CDev\PINCodes\API\Endpoint\ProductPINCode\Transformer\OutputTransformerInterface: '@CDev\PINCodes\API\Endpoint\ProductPINCode\Transformer\OutputTransformer'
  CDev\PINCodes\API\Endpoint\ProductPINCode\Transformer\OutputTransformer: ~
  CDev\PINCodes\API\Endpoint\ProductPINCode\Transformer\InputTransformerInterface: '@CDev\PINCodes\API\Endpoint\ProductPINCode\Transformer\InputTransformer'
  CDev\PINCodes\API\Endpoint\ProductPINCode\Transformer\InputTransformer: ~

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

  CDev\PINCodes\API\Endpoint\ProductPINCode\DataProvider\CollectionDataProvider:
    arguments:
      $inner: '@api_platform.doctrine.orm.default.collection_data_provider'
      $repository: '@xcart.repository.product'

  CDev\PINCodes\API\Endpoint\ProductPINCode\DataProvider\ItemDataProvider:
    arguments:
      $inner: '@api_platform.doctrine.orm.default.item_data_provider'
      $repository: '@xcart.repository.product'

  CDev\PINCodes\API\Endpoint\ProductPINCode\DataPersister\DataPersister:
    arguments:
      $inner: '@api_platform.doctrine.orm.data_persister'

  xcart.api.xc.pin_codes.product_pin_code.controller:
    class: CDev\PINCodes\Controller\API\ProductPINCode\Post
    arguments:
      $repository: '@xcart.repository.product'

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

  xcart.cdev.pincodes.api.product.input.rule_set:
    class: XLite\API\InputRule\RuleSet
    decorates: CDev\PINCodes\API\Endpoint\ProductPINCode\Transformer\InputTransformer
    arguments:
      $subRules:
        - '@xcart.api.profile.sub_rule.check_unique_login'

  xcart.cdev.pincodes.api.product.sub_rule.check_unique_code:
    class: CDev\PINCodes\API\Endpoint\ProductPINCode\InputRule\SubRule\CheckUniqueCode
    arguments:
      $repository: '@xcart.repository.cdev.pincodes.pincode'
      $entityFieldName: 'code'

  xcart.repository.cdev.pincodes.pincode:
    class: CDev\PINCodes\Model\Repo\PinCode
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
      - CDev\PINCodes\Model\PinCode

  xcart.api.cdev.pincodes.product_pin_code.sub_extension:
    class: CDev\PINCodes\API\Endpoint\ProductPINCode\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]

  CDev\PINCodes\EntityCallback\PinCodeCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: CDev\PINCodes\Model\PinCode}

  CDev\PINCodes\EntityCallback\ProductCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: preRemove, entity: XLite\Model\Product, priority: 500}
