#
# 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:
      static_page: domain/goalpage

dto_generator:
  entities:
    api:
      XCart\API\Entity\Storefront\Menu:
        name: Menu
        logicEntity: XCart\Logic\Entity\Storefront\Menu
        path: /storefront/menus
        register_get_one: true
        register_get_collection: true
        filters:
          - className: XCart\Bundle\APIPlatformBridgeBundle\Filter\StringFilter
            properties: [type]
            operations: [get]
          - className: XCart\Bundle\APIPlatformBridgeBundle\Filter\IdIntegerFilter
            properties: [parent]
            operations: [get]
        fields:
          name:
            type: string
            nullable: true
          link:
            type: string
            nullable: true
          submenuCount:
            type: integer

      XCart\API\Entity\Storefront\StaticPage:
        name: Static Page
        logicEntity: XCart\Logic\Entity\Storefront\StaticPage
        path: /storefront/pages
        register_get_one: true
        register_get_collection: true
        itemOperations:
          getByCleanURL:
            method: GET
            path: /storefront/pages/by_clean_url/{clean_url}
            requirements:
              clean_url: '\S+'
            identifiers: [clean_url]
            openapi_context:
              summary: 'Retrieve a static page by clean url'
        fields:
          name:
            type: string
          cleanUrl:
            type: string
            nullable: true
          body:
            type: string
          metaDescription:
            type: string
          metaKeywords:
            type: string
          metaTitle:
            type: string
          image:
            type: XCart\API\Entity\Storefront\Image
            nullable: true

    logic:
      XCart\Logic\Entity\Storefront\Menu:
        doctrineEntity: CDev\SimpleCMS\Model\Menu
        generate_get_one: true
        generate_get_collection: true
        use_doctrine_get_one: true
        use_doctrine_get_collection: true
        fields:
          name:
            type: string
            nullable: true
          link:
            type: string
            nullable: true
          submenuCount:
            type: integer
          parentId:
            type: integer
      XCart\Logic\Entity\Storefront\StaticPage:
        doctrineEntity: CDev\SimpleCMS\Model\Page
        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
            nullable: true
          body:
            type: string
          metaDescription:
            type: string
          metaKeywords:
            type: string
          metaTitle:
            type: string
          image:
            type: XCart\Logic\Entity\Storefront\Image
            nullable: true

    dto:
      XCart\Logic\Action\Storefront\Menu\GetList\DTO\Request\Filter:
        type: logic_request_get_list_filter
        fields:
          type:
            type: StringValue
            nullable: true
          parent:
            type: IntegerValue
            nullable: true

      XCart\DTO\Doctrine\Storefront\Menu\OrderRule:
        type: doctrine_entity_order_rule
        fields:
          position:
            type: string
            nullable: true

      XCart\DTO\Doctrine\Storefront\Menu\Filter:
        type: doctrine_entity_filter
        fields:
          type:
            type: StringValue
            nullable: true
          parent:
            type: IntegerValue
            nullable: true
          enabled:
            type: BooleanValue
            nullable: true
          visibleFor:
            type: StringListValue

      XCart\Logic\Action\Storefront\StaticPage\GetList\DTO\Request\Filter:
        type: logic_request_get_list_filter
        fields:
          cleanURL:
            type: StringValue
            nullable: true

      XCart\DTO\Doctrine\Storefront\StaticPage\OrderRule:
        type: doctrine_entity_order_rule
        fields:
          position:
            type: string
            nullable: true

      XCart\DTO\Doctrine\Storefront\StaticPage\Filter:
        type: doctrine_entity_filter
        fields:
          type:
            type: StringValue
          enabled:
            type: BooleanValue
            nullable: true

    logic_request:
      XCart\Logic\Action\Storefront\Menu\GetList\DTO\Request:
        type: get_collection
        entity: XCart\Logic\Entity\Storefront\Menu
        interfaces:
          - XCart\Logic\DTO\Request\ProfileOwnerRequestInterface
        traits:
          - XCart\Logic\DTO\Request\ProfileOwnerRequestTrait

      XCart\Logic\Action\Storefront\Menu\GetOne\DTO\Request:
        type: get_one
        entity: XCart\Logic\Entity\Storefront\Menu
        interfaces:
          - XCart\Logic\DTO\Request\ProfileOwnerRequestInterface
        traits:
          - XCart\Logic\DTO\Request\ProfileOwnerRequestTrait

  transformers:
    - from: CDev\SimpleCMS\Model\Menu
      to: XCart\Logic\Entity\Storefront\Menu
    - from: CDev\SimpleCMS\Model\Page
      to: XCart\Logic\Entity\Storefront\StaticPage

services:
  _defaults:
    autowire: true
    autoconfigure: true

  CDev\SimpleCMS\Storage\ConfigTermUrlStorage: ~

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

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

  # repositories
  xcart.repository.menu.read:
    class: CDev\SimpleCMS\Model\Repo\MenuRead
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    calls:
      - [setQueryBuilderFactory, ['@xcart.query_builder.factory.menu.read']]
    arguments:
      - CDev\SimpleCMS\Model\Menu

  xcart.repository.page.read:
    class: CDev\SimpleCMS\Model\Repo\Page
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    calls:
      - [setQueryBuilderFactory, ['@xcart.query_builder.factory.staticpage.read']]
    arguments:
      - CDev\SimpleCMS\Model\Page

  # menu: read
  xcart.data_source.menu.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.menu.read'
      $collectionClassName: CDev\SimpleCMS\Entity\MenuCollection

  # page: read
  xcart.data_source.page.read:
    class: XCart\Bundle\DoctrineBridgeBundle\DataSource\DoctrineReadDataSource
    arguments:
      $repository: '@xcart.repository.page.read'
      $collectionClassName: CDev\SimpleCMS\Entity\PageCollection

  CDev\SimpleCMS\Transformer\CDev\SimpleCMS\Model\Menu\Logic\Entity\Storefront\MenuDecorator:
    decorates: 'XCart\Transformer\CDev\SimpleCMS\Model\Menu\Logic\Entity\Storefront\Menu'
    arguments:
      $inner: '@.inner'

  CDev\SimpleCMS\Transformer\CDev\SimpleCMS\Model\Page\Logic\Entity\Storefront\StaticPageDecorator:
    decorates: 'XCart\Transformer\CDev\SimpleCMS\Model\Page\Logic\Entity\Storefront\StaticPage'
    arguments:
      $inner: '@.inner'

  # get list
  xcart.doctrine.storefront.menu.criteria.assembler.decorator.type:
    class: CDev\SimpleCMS\Action\Storefront\Menu\Assembler\Criteria\FindListCriteriaAssemblerDecorator
    decorates: xcart.doctrine.storefront.menu.criteria.assembler
    decoration_priority: 10
    arguments:
      $inner: '@.inner'
  xcart.doctrine.storefront.staticpage.criteria.assembler.decorator.type:
    class: CDev\SimpleCMS\Action\Storefront\StaticPage\Assembler\Criteria\FindListCriteriaAssemblerDecorator
    decorates: xcart.doctrine.storefront.staticpage.criteria.assembler
    decoration_priority: 10
    arguments:
      $inner: '@.inner'

  xcart.api.storefront.staticpage.data_provider.item.request.assembler.get_one_by_clean_url:
    class: CDev\SimpleCMS\API\Endpoint\Storefront\StaticPage\GetOneByCleanURL\Assembler\RequestAssembler
    arguments:
      $pageRepository: '@xcart.repository.page.read'

  xcart.api.storefront.staticpage.data_provider.item.get_by_clean_url:
    class: XCart\Bundle\APIPlatformBridgeBundle\API\DataProvider\Item\DataProvider
    arguments:
      $classes: [XCart\API\Entity\Storefront\StaticPage]
      $action: '@xcart.logic.storefront.staticpage.get_one.action'
      $requestAssembler: '@xcart.api.storefront.staticpage.data_provider.item.request.assembler.get_one_by_clean_url'
      $responseAssembler: '@xcart.api.storefront.staticpage.data_provider.item.response.assembler'
      $operationNames: [getByCleanURL]

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

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

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

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

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