#
# 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:
      # wishlist
      XCart\API\Entity\Storefront\Wishlist:
        name: Wishlist
        logicEntity: XCart\Logic\Entity\Storefront\Wishlist
        path: /storefront/wishlist
        register_get_one: true
        annotations:
          - _: ApiResource
            itemOperations:
              get:
                method: GET
                path: /storefront/wishlist
                identifiers: []
                normalization_context:
                  skip_null_values: false
                  groups: ['read']
                openapi_context:
                  summary: 'Retrieve the wishlist'
              getByHash:
                method: GET
                path: /storefront/wishlist/by_hash/{hash}
                requirements:
                  hash: '[a-zA-Z0-9]{7}'
                identifiers: [hash]
                openapi_context:
                  summary: 'Retrieve the wishlist by hash'
        fields:
          hash:
            type: string
            nullable: true
          productIds:
            type: int[]

      XCart\API\Entity\Storefront\Wishlist\ClearRequest:
        name: Wishlist clear request
        logicEntity: XCart\Logic\Entity\Storefront\Wishlist\ClearRequest
        path: /storefront/wishlist/clear
        register_create_one: true
        annotations:
          - _: ApiResource
            collectionOperations:
              clear:
                method: POST
                path: /storefront/wishlist/clear
                identifiers: []
                openapi_context:
                  summary: 'Clear the wishlist'

      XCart\API\Entity\Storefront\Wishlist\MergeRequest:
        name: Wishlist merge request
        logicEntity: XCart\Logic\Entity\Storefront\Wishlist\MergeRequest
        path: /storefront/wishlist/merge
        register_create_one: true
        annotations:
          - _: ApiResource
            collectionOperations:
              merge:
                method: POST
                path: /storefront/wishlist/merge
                denormalization_context:
                  groups: [insert]
                identifiers: []
                openapi_context:
                  summary: 'Add one or more products to wishlist'
        fields:
          productIds:
            type: int[]
            groups: [insert]

      # wishlistLink (wishlistProduct)
      XCart\API\Entity\Storefront\WishlistLink:
        name: Wishlist Product
        logicEntity: XCart\Logic\Entity\Storefront\WishlistLink
        path: /storefront/wishlist/product
        register_get_one: true
        register_delete_one: true
        register_create_one: true
        fields:
          productId:
            type: int
            groups: [insert]
            annotations:
              Assert\NotBlank: ~
        itemOperations:
          get:
            method: GET
            path: /storefront/wishlist/product/{id}
            identifiers: [id]
            openapi_context:
              parameters:
                - in: path
                  name: id
                  schema:
                    type: integer
                  required: true
                  description: product id
          delete:
            method: DELETE
            path: /storefront/wishlist/product/{id}
            identifiers: [id]
            openapi_context:
              summary: 'Delete product from wishlist'
              parameters:
                - in: path
                  name: id
                  schema:
                    type: integer
                  required: true
                  description: product id
        collectionOperations:
          post:
            method: POST
            path: /storefront/wishlist/product
            openapi_context:
              summary: 'Add product to wishlist'

    logic:
      # wishlist
      XCart\Logic\Entity\Storefront\Wishlist:
        doctrineEntity: QSL\MyWishlist\Model\Wishlist
        generate_get_one: true
        use_doctrine_get_one: true
        fields:
          hash:
            type: string
            nullable: true
          productIds:
            type: int[]

      XCart\Logic\Entity\Storefront\Wishlist\ClearRequest:
        generate_create_one: true

      XCart\Logic\Entity\Storefront\Wishlist\MergeRequest:
        generate_create_one: true
        fields:
          productIds:
            type: int[]

      # wishlistLink (wishlistProduct)
      XCart\Logic\Entity\Storefront\WishlistLink:
        doctrineEntity: QSL\MyWishlist\Model\WishlistLink
        generate_get_one: true
        generate_delete_one: true
        generate_create_one: true
        use_doctrine_get_one: true
        use_doctrine_delete_one: true
        use_doctrine_create_one: true
        fields:
          productId:
            type: int
          wishlist_id:
            type: int
          orderby:
            type: int
          creationDate:
            type: int

    logic_request:
      XCart\Logic\Action\Storefront\Wishlist\GetOne\DTO\Request:
        type: get_one
        entity: XCart\Logic\Entity\Storefront\Wishlist
        interfaces:
          - XCart\Logic\DTO\Request\ProfileRequestInterface
        traits:
          - XCart\Logic\DTO\Request\ProfileRequestTrait

      XCart\Logic\Action\Storefront\WishlistLink\GetOne\DTO\Request:
        type: get_one
        entity: XCart\Logic\Entity\Storefront\WishlistLink
        interfaces:
          - XCart\Logic\DTO\Request\ProfileRequestInterface
        traits:
          - XCart\Logic\DTO\Request\ProfileRequestTrait

      XCart\Logic\Action\Storefront\WishlistLink\CreateOne\DTO\Request:
        type: create_one
        entity: XCart\Logic\Entity\Storefront\NewWishlistLink
        interfaces:
          - XCart\Logic\DTO\Request\ProfileRequestInterface
        traits:
          - XCart\Logic\DTO\Request\ProfileRequestTrait

      XCart\Logic\Action\Storefront\Wishlist\MergeRequest\CreateOne\DTO\Request:
        type: create_one
        entity: XCart\Logic\Entity\Storefront\Wishlist\NewMergeRequest
        interfaces:
          - XCart\Logic\DTO\Request\ProfileRequestInterface
        traits:
          - XCart\Logic\DTO\Request\ProfileRequestTrait

      XCart\Logic\Action\Storefront\Wishlist\ClearRequest\CreateOne\DTO\Request:
        type: create_one
        entity: XCart\Logic\Entity\Storefront\Wishlist\NewClearRequest
        interfaces:
          - XCart\Logic\DTO\Request\ProfileRequestInterface
        traits:
          - XCart\Logic\DTO\Request\ProfileRequestTrait

  transformers:
    - from: QSL\MyWishlist\Model\Wishlist
      to: XCart\Logic\Entity\Storefront\Wishlist

    - from: QSL\MyWishlist\Model\WishlistLink
      to: XCart\Logic\Entity\Storefront\WishlistLink
    - from: QSL\MyWishlist\Model\WishlistLink
      to: XCart\Logic\Entity\Storefront\NewWishlistLink
    - from: XCart\Logic\Entity\Storefront\WishlistLink
      to: QSL\MyWishlist\Model\WishlistLink
    - from: XCart\Logic\Entity\Storefront\NewWishlistLink
      to: QSL\MyWishlist\Model\WishlistLink
    - from: XCart\API\Entity\Storefront\WishlistLink
      to: XCart\Logic\Entity\Storefront\NewWishlistLink

services:
  _defaults:
    autowire: true
    autoconfigure: true

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

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

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

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

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

  # repositories
  xcart.repository.wishlist.read:
    class: QSL\MyWishlist\Model\Repo\Wishlist
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    calls:
      - [setQueryBuilderFactory, ['@xcart.query_builder.factory.wishlist.read']]
    arguments:
      - QSL\MyWishlist\Model\Wishlist

  xcart.repository.wishlist.write:
    class: QSL\MyWishlist\Model\Repo\Wishlist
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    calls:
      - [setQueryBuilderFactory, ['@xcart.query_builder.factory.wishlist.write']]
    arguments:
      - QSL\MyWishlist\Model\Wishlist

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

  xcart.repository.wishlistlink.write:
    class: QSL\MyWishlist\Model\Repo\WishlistLink
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    calls:
      - [setQueryBuilderFactory, ['@xcart.query_builder.factory.wishlistlink.write']]
    arguments:
      - QSL\MyWishlist\Model\WishlistLink

  # transformer
  QSL\MyWishlist\Transformer\QSL\MyWishlist\Model\Wishlist\Logic\Entity\Storefront\WishlistDecorator:
    decorates: 'XCart\Transformer\QSL\MyWishlist\Model\Wishlist\Logic\Entity\Storefront\Wishlist'

  QSL\MyWishlist\Transformer\QSL\MyWishlist\Model\WishlistLink\Logic\Entity\Storefront\NewWishlistLinkDecorator:
    decorates: 'XCart\Transformer\QSL\MyWishlist\Model\WishlistLink\Logic\Entity\Storefront\NewWishlistLink'

  QSL\MyWishlist\Transformer\QSL\MyWishlist\Model\WishlistLink\Logic\Entity\Storefront\WishlistLinkDecorator:
    decorates: 'XCart\Transformer\QSL\MyWishlist\Model\WishlistLink\Logic\Entity\Storefront\WishlistLink'

  QSL\MyWishlist\Transformer\Logic\Entity\Storefront\NewWishlistLink\QSL\MyWishlist\Model\WishlistLinkDecorator:
    decorates: 'XCart\Transformer\Logic\Entity\Storefront\NewWishlistLink\QSL\MyWishlist\Model\WishlistLink'
    arguments:
      $productReadRepository: '@xcart.repository.product.read'
      $wishlistLinkReadRepository: '@xcart.repository.wishlistlink.read'
      $wishlistReadRepository: '@xcart.repository.wishlist.read'

  # read
  xcart.data_source.wishlist.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.wishlist.read'
      $collectionClassName: QSL\MyWishlist\Entity\WishlistCollection

  xcart.data_source.wishlistlink.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.wishlistlink.read'
      $collectionClassName: QSL\MyWishlist\Entity\WishlistLinkCollection

  # get one
  xcart.api.storefront.wishlist.data_provider.item.request.assembler.decorator.profile:
    class: XCart\API\Endpoint\Storefront\Common\DataProvider\Assembler\RequestAssemblerWithProfileDecorator
    decorates: xcart.api.storefront.wishlist.data_provider.item.request.assembler
    arguments:
      $inner: '@.inner'

  xcart.api.storefront.wishlist.data_provider.item.get_one.self:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\Wishlist]
      $action: '@xcart.logic.storefront.wishlist.get_one_self.action'
      $requestAssembler: '@xcart.api.storefront.wishlist.data_provider.item.request.assembler'
      $responseAssembler: '@xcart.api.storefront.wishlist.data_provider.item.response.assembler'
      $operationNames: [get]

  xcart.api.storefront.wishlist.data_provider.item.request.assembler.decorator.without_id:
    class: XCart\API\DataProvider\Storefront\Item\Assembler\WithoutIdRequestAssembler
    decorates: xcart.api.storefront.wishlist.data_provider.item.request.assembler
    arguments:
      $inner: '@.inner'
      $requestFactory: '@XCart\Factory\Logic\Action\Storefront\Wishlist\GetOne\DTO\RequestInterface'

  xcart.logic.storefront.wishlist.get_one_self.action:
    class: QSL\MyWishlist\Action\Storefront\Wishlist\GetOne\Action
    arguments:
      $readRepository: '@xcart.repository.wishlist.read'
      $responseAssembler: '@xcart.logic.storefront.wishlist.get_one.response.assembler'
    tags:
      - {name: xcart.logic.action, request: \XCart\Logic\Action\Storefront\Wishlist\GetOne\DTO\Request, response: \XCart\Logic\Action\Storefront\Wishlist\GetOne\DTO\Response}

  # get one by hash
  xcart.api.storefront.wishlist.data_provider.item.request.assembler.get_one_by_hash:
    class: QSL\MyWishlist\API\Storefront\Wishlist\DataProvider\GetOneByHash\Assembler\RequestAssembler
    arguments:
      $wishlistRepository: '@xcart.repository.wishlist.read'

  xcart.api.storefront.wishlist.data_provider.item.request.assembler.get_one_by_hash.decorator.profile:
    class: XCart\API\Endpoint\Storefront\Common\DataProvider\Assembler\RequestAssemblerWithProfileDecorator
    decorates: xcart.api.storefront.wishlist.data_provider.item.request.assembler
    arguments:
      $inner: '@.inner'

  xcart.api.storefront.wishlist.data_provider.item.get_by_hash:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\Wishlist]
      $action: '@xcart.logic.storefront.wishlist.get_one.action'
      $requestAssembler: '@xcart.api.storefront.wishlist.data_provider.item.request.assembler.get_one_by_hash'
      $responseAssembler: '@xcart.api.storefront.wishlist.data_provider.item.response.assembler'
      $operationNames: [getByHash]

  # get one link
  xcart.api.storefront.wishlist_link.data_provider.item.request.assembler.decorator.profile:
    class: XCart\API\Endpoint\Storefront\Common\DataProvider\Assembler\RequestAssemblerWithProfileDecorator
    decorates: xcart.api.storefront.wishlistlink.data_provider.item.request.assembler
    arguments:
      $inner: '@.inner'

  xcart.logic.storefront.wishlistlink.get_one.action:
    class: QSL\MyWishlist\Action\Storefront\WishlistLink\GetOne\Action
    arguments:
      $productRepository: '@xcart.repository.product.read'
      $wishlistLinkRepository: '@xcart.repository.wishlistlink.read'
      $wishlistRepository: '@xcart.repository.wishlist.read'
      $responseAssembler: '@xcart.logic.storefront.wishlistlink.get_one.response.assembler'
    tags:
      - {name: xcart.logic.action, request: \XCart\Logic\Action\Storefront\WishlistLink\GetOne\DTO\Request, response: \XCart\Logic\Action\Storefront\WishlistLink\GetOne\DTO\Response}

  # create one
  xcart.api.storefront.wishlistlink.data_persister.persister.request.assembler.create.decorator.profile:
    class: XCart\API\Endpoint\Storefront\Common\DataPersister\Persister\Assembler\CreatePayloadAssemblerWithProfileDecorator
    decorates: xcart.api.storefront.wishlistlink.data_persister.persister.request.assembler.create
    arguments:
      $inner: '@.inner'

  xcart.logic.storefront.wishlistlink.create_one.action:
    class: QSL\MyWishlist\Action\Storefront\WishlistLink\CreateOne\Action
    arguments:
      $productReadRepository: '@xcart.repository.product.read'
      $wishlistWriteRepository: '@xcart.repository.wishlist.write'

  # clear wishlist
  xcart.api.storefront.wishlist.clearrequest.data_persister.persister.request.assembler.create.decorator.profile:
    class: XCart\API\Endpoint\Storefront\Common\DataPersister\Persister\Assembler\CreatePayloadAssemblerWithProfileDecorator
    decorates: xcart.api.storefront.wishlist.clearrequest.data_persister.persister.request.assembler.create
    arguments:
      $inner: '@.inner'

  xcart.logic.storefront.wishlist.clearrequest.create_one.action:
    class: QSL\MyWishlist\Action\Storefront\WishlistClearRequest\CreateOne\Action
    arguments:
      $wishlistReadRepository: '@xcart.repository.wishlist.read'
      $wishlistLinkWriteRepository: '@xcart.repository.wishlistlink.write'
    tags:
      - {name: xcart.logic.action, request: \XCart\Logic\Action\Storefront\Wishlist\ClearRequest\CreateOne\DTO\Request, response: \XCart\Logic\Action\Storefront\Wishlist\ClearRequest\CreateOne\DTO\Response}

  # merge wishlist
  xcart.api.storefront.wishlist.mergerequest.data_persister.persister.request.assembler.create.decorator.profile:
    class: XCart\API\Endpoint\Storefront\Common\DataPersister\Persister\Assembler\CreatePayloadAssemblerWithProfileDecorator
    decorates: xcart.api.storefront.wishlist.mergerequest.data_persister.persister.request.assembler.create
    arguments:
      $inner: '@.inner'

  xcart.logic.storefront.wishlist.mergerequest.create_one.action:
    class: QSL\MyWishlist\Action\Storefront\WishlistMergeRequest\CreateOne\Action
    arguments:
      $productReadRepository: '@xcart.repository.product.read'
      $wishlistWriteRepository: '@xcart.repository.wishlist.write'
    tags:
      - {name: xcart.logic.action, request: \XCart\Logic\Action\Storefront\Wishlist\MergeRequest\CreateOne\DTO\Request, response: \XCart\Logic\Action\Storefront\Wishlist\MergeRequest\CreateOne\DTO\Response}
