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

dto_generator:
  entities:
    api:
      XCart\API\Entity\Storefront\Currency:
        name: Currency
        logicEntity: XCart\Logic\Entity\Storefront\Currency
        path: /storefront/currencies
        register_get_one: true
        register_get_collection: true
        itemOperations:
          getByCode:
            method: GET
            path: /storefront/currencies/by_code/{code}
            requirements:
              code: '[a-zA-Z]{3}'
            identifiers: [code]
            openapi_context:
              summary: 'Retrieve a currency by code'
        fields:
          code:
            type: string
          rate:
            type: float
          prefix:
            type: string
          suffix:
            type: string
          precision:
            type: int
          decimalDelimiter:
            type: string
          thousandDelimiter:
            type: string
          default:
            type: bool
          countries:
            type: array
      XCart\API\Entity\Storefront\Country:
        fields:
          activeCurrency:
            type: string
            nullable: true

    logic:
      XCart\Logic\Entity\Storefront\Currency:
        doctrineEntity: XC\MultiCurrency\Model\ActiveCurrency
        generate_get_one: true
        generate_get_collection: true
        use_doctrine_get_one: true
        use_doctrine_get_collection: true
        fields:
          code:
            type: string
          rate:
            type: float
          prefix:
            type: string
          suffix:
            type: string
          precision:
            type: int
          decimalDelimiter:
            type: string
          thousandDelimiter:
            type: string
          default:
            type: bool
          countries:
            type: array
      XCart\Logic\Entity\Storefront\Country:
        fields:
          activeCurrency:
            type: string
            nullable: true

    dto:
      XCart\DTO\Doctrine\Storefront\Currency\Filter:
        type: doctrine_entity_filter
        fields:
          enabled:
            type: BooleanValue
            nullable: true
      XCart\DTO\Doctrine\Storefront\Currency\OrderRule:
        type: doctrine_entity_order_rule
        fields:
          position:
            type: string
            nullable: true
  transformers:
    - from: XC\MultiCurrency\Model\ActiveCurrency
      to: XCart\Logic\Entity\Storefront\Currency

services:
  _defaults:
    autowire: true
    autoconfigure: true

  XC\MultiCurrency\Core\RateProvider\FreeCurrencyConverterAPI:
    public: true

  XC\MultiCurrency\Core\RateProvider\CurrencyConverterAPI:
    public: true

  XC\MultiCurrency\Core\Task\UpdateRates:
    tags:
      - {name: kernel.event_listener, event: xcart.cronjob, method: handleTask}

  # repositories
  xcart.repository.currency.read:
    class: XC\MultiCurrency\Model\Repo\ActiveCurrency
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    calls:
      - [setQueryBuilderFactory, ['@xcart.query_builder.factory.activecurrency.read']]
    arguments:
      - XC\MultiCurrency\Model\ActiveCurrency

  xcart.query_builder.factory.activecurrency.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.activecurrency.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.currency.read'
      $collectionClassName: XC\MultiCurrency\Entity\ActiveCurrencyCollection

  # transformer decorator
  XC\MultiCurrency\Transformer\XC\MultiCurrency\Model\ActiveCurrency\Logic\Entity\Storefront\CurrencyDecorator:
    decorates: XCart\Transformer\XC\MultiCurrency\Model\ActiveCurrency\Logic\Entity\Storefront\Currency
    arguments:
      $inner: '@.inner'

  XC\MultiCurrency\Transformer\XLite\Model\Country\Logic\Entity\CountryDecorator:
    decorates: XCart\Transformer\XLite\Model\Country\Logic\Entity\Storefront\Country
    arguments:
      $inner: '@.inner'

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

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

  xcart.api.storefront.currency.data_provider.item.request.assembler.get_one_by_code:
    class: XC\MultiCurrency\API\Endpoint\Storefront\Currency\GetOneByCleanURL\Assembler\RequestAssembler
    arguments:
      $pageRepository: '@xcart.repository.currency.read'

  xcart.api.storefront.currency.data_provider.item.get_by_code:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\Currency]
      $action: '@xcart.logic.storefront.currency.get_one.action'
      $requestAssembler: '@xcart.api.storefront.currency.data_provider.item.request.assembler.get_one_by_code'
      $responseAssembler: '@xcart.api.storefront.currency.data_provider.item.response.assembler'
      $operationNames: [getByCode]

  # assemblers
  xcart.doctrine.storefront.activecurrency.criteria.assembler.decorator.type:
    class: XC\MultiCurrency\Action\Storefront\Currency\Assembler\Criteria\FindListCriteriaAssemblerDecorator
    decorates: xcart.doctrine.storefront.currency.criteria.assembler
    decoration_priority: 10
    arguments:
      '$inner': '@.inner'

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