services:
    oro_rfp.mailer.processor:
        class: 'Oro\Bundle\RFPBundle\Mailer\Processor'
        public: false
        arguments:
            - "@oro_user.mailer.user_template_email_sender"

    oro_rfp.mailer.request_representatives_notifier:
        class: 'Oro\Bundle\RFPBundle\Mailer\RequestRepresentativesNotifier'
        arguments:
            - "@oro_rfp.mailer.processor"
            - "@oro_config.manager"

    oro_rfp.processor.quick_add:
        class: 'Oro\Bundle\RFPBundle\ComponentProcessor\DataStorageComponentProcessor'
        public: true
        arguments:
            - '@oro_product.storage.product_data_storage'
            - '@oro_product.component_processor.quick_add_product_mapper'
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
            - '@request_stack'
            - '@translator'
            - '@router'
            - '@oro_rfp.provider.product_rfp_availability'
            - '@oro_featuretoggle.checker.feature_checker'
        calls:
            - [setRedirectRouteName, ['oro_rfp_frontend_request_create']]
            - [setAcl, ['oro_rfp_frontend_request_create']]
        tags:
            - { name: oro_product.quick_add_processor, processor_name: oro_rfp_quick_add_processor }

    oro_rfp.event_listener.product_db_query_restriction:
        class: 'Oro\Bundle\ProductBundle\EventListener\ScopedProductDBQueryRestrictionEventListener'
        parent: oro_product.event_listener.abstract_product_db_query_restriction
        calls:
            - [setScope, ['rfp']]
            - [setFrontendSystemConfigurationPath, ['oro_rfp.frontend_product_visibility']]
            - [setBackendSystemConfigurationPath, ['oro_rfp.backend_product_visibility']]
        tags:
            - { name: kernel.event_listener, event: oro_product.product_db_query.restriction, method: onDBQuery }

    oro_rfp.event_listener.product_search_query_restriction:
        class: 'Oro\Bundle\ProductBundle\EventListener\ScopedProductSearchQueryRestrictionEventListener'
        parent: oro_product.event_listener.abstract_product_search_query_restriction
        calls:
            - [setScope, ['rfp']]
            - [setRequestStack, ['@request_stack']]
            - [setFrontendSystemConfigurationPath, ['oro_rfp.frontend_product_visibility']]
        tags:
            - { name: kernel.event_listener, event: oro_product.product_search_query.restriction, method: onSearchQuery }

    oro_rfp.service.request_to_quote_data_storage:
        class: 'Oro\Bundle\RFPBundle\Storage\RequestToQuoteDataStorage'
        public: true
        arguments:
            - "@oro_product.storage.product_data_storage"

    oro_rfp.service.request_update_handler:
        class: 'Oro\Bundle\RFPBundle\Form\Handler\RequestUpdateHandler'
        public: true
        parent: oro_form.update_handler
        calls:
            - [setRepresentativesNotifier, ['@oro_rfp.mailer.request_representatives_notifier']]
            - [setAuthorizationChecker, ['@security.authorization_checker']]
            - [setSymfonyRouter, ['@router']]

    oro_rfp.storage.offers_data_storage:
        class: 'Oro\Bundle\RFPBundle\Storage\OffersDataStorage'
        public: true
        parent: oro_product.storage.session_data_storage

    oro_rfp.storage.offers_form_storage:
        class: 'Oro\Bundle\RFPBundle\Storage\OffersFormStorage'
        public: false

    oro_rfp.layout.data_provider.request_form:
        class: 'Oro\Bundle\RFPBundle\Layout\DataProvider\RFPFormProvider'
        public: true
        arguments:
            - '@form.factory'
            - '@router'
        tags:
            - { name: layout.data_provider, alias: oro_rfp_request_form }

    oro_rfp.layout.data_provider.rfp_product_prices:
        class: 'Oro\Bundle\RFPBundle\Layout\DataProvider\RfpProductPricesProvider'
        arguments:
            - '@oro_pricing.layout.data_provider.frontend_product_prices'
        tags:
            - { name: layout.data_provider, alias: oro_rfp_product_prices }

    oro_rfp.layout.data_provider.request_product_prices:
        class: 'Oro\Bundle\RFPBundle\Layout\DataProvider\RequestProductPricesProvider'
        arguments:
            - '@oro_rfp.provider.request_product_line_item_tier_prices'
        tags:
            - { name: layout.data_provider, alias: oro_rfp_request_product_prices }

    oro_rfp.request.manager:
        class: 'Oro\Bundle\RFPBundle\Model\RequestManager'
        public: true
        arguments:
            - '@oro_security.token_accessor'
            - '@oro_entity.doctrine_helper'
            - '@oro_customer.manager.guest_customer_user'
            - '@oro_website.manager'

    oro_rfp.event_listener.customer_view:
        class: 'Oro\Bundle\RFPBundle\EventListener\CustomerViewListener'
        public: true
        arguments:
            - '@translator'
            - '@oro_entity.doctrine_helper'
            - '@request_stack'
        tags:
            - { name: kernel.event_listener, event: oro_ui.scroll_data.before.customer-view, method: onCustomerView }
            - { name: kernel.event_listener, event: oro_ui.scroll_data.before.customer-user-view, method: onCustomerUserView }
            - { name: oro_featuretogle.feature, feature: 'rfp' }

    oro_rfp.provider.quote_currency_checker:
        class: Oro\Bundle\RFPBundle\Provider\CurrencyCheckerProvider
        public: false
        arguments:
            - '@doctrine'
        tags:
            - { name: oro_multi_currency.currency_checker_provider }

    oro_rfp.provider.product_rfp_availability:
       class: Oro\Bundle\RFPBundle\Provider\ProductRFPAvailabilityProvider
       arguments:
           - '@oro_config.manager'
           - '@doctrine'
           - '@oro_security.acl_helper'
       calls:
           - setNotAllowedProductTypes:
               -
                   - !php/const Oro\Bundle\ProductBundle\Entity\Product::TYPE_CONFIGURABLE

    oro_rfp.acl.voter.frontend_request:
        class: Oro\Bundle\RFPBundle\Acl\Voter\FrontendRequestVoter
        public: false
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_frontend.request.frontend_helper'
            - '@Psr\Container\ContainerInterface'
        calls:
            - [setClassName, ['Oro\Bundle\RFPBundle\Entity\Request']]
        tags:
            - { name: security.voter }
            - { name: container.service_subscriber, id: oro_workflow.manager }

    oro_rfp.datagrid.listener.column:
        class: 'Oro\Bundle\RFPBundle\EventListener\RFPDatagridColumnListener'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.rfp-requests-grid, method: onBuildBefore }
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.frontend-requests-grid, method: onBuildBefore }

    oro_rfp.event_listener.navigation:
        class: 'Oro\Bundle\RFPBundle\EventListener\NavigationListener'
        arguments:
            - "@security.authorization_checker"
            - "@oro_featuretoggle.checker.feature_checker"
            - "@oro_frontend.request.frontend_helper"
        tags:
            - { name: kernel.event_listener, event: oro_menu.configure.oro_customer_menu, method: onNavigationConfigure }
            - { name: kernel.event_listener, event: oro_menu.configure.oro_customer_menu_refreshing_teal, method: onNavigationConfigure }

    oro_rfp.voter.guest_rfp:
        parent: oro_customer.voter.anonymous_customer_user
        calls:
            - [ setFeatureName, ['guest_rfp'] ]
        tags:
            - { name: oro_featuretogle.voter }

    oro_rfp.voter.customer_user_rfp:
        parent: oro_customer.voter.customer_user
        calls:
            - [ setFeatureName, ['guest_rfp'] ]
        tags:
            - { name: oro_featuretogle.voter }

    oro_rfp.voter.guest_quick_order_form:
        parent: oro_product.voter.guest_quick_order_form
        calls:
            - [ setFeatureName, ['guest_rfp'] ]
        tags:
            - { name: oro_featuretogle.voter }

    oro_rfp.listener.rfp:
        class: 'Oro\Bundle\RFPBundle\EventListener\RFPListener'
        arguments:
            - '@oro_user.provider.default_user'
            - '@oro_security.token_accessor'
            - '@oro_customer.manager.guest_customer_user'
        tags:
            - { name: doctrine.orm.entity_listener, entity: 'Oro\Bundle\RFPBundle\Entity\Request', event: prePersist }

    oro_rfp.event_listener.system_config.default_guest_rfp_owner:
        class: Oro\Bundle\UserBundle\EventListener\DefaultUserSystemConfigListener
        arguments:
            - '@oro_user.provider.default_user'
            - '@doctrine'
            - 'oro_rfp.default_guest_rfp_owner'
        tags:
            - { name: kernel.event_listener, event: oro_config.settings_form_preset, method: onFormPreSetData }
            - { name: kernel.event_listener, event: oro_config.settings_before_save, method: onSettingsSaveBefore }

    oro_rfp.twig.request_products:
        class: 'Oro\Bundle\RFPBundle\Twig\RequestProductsExtension'
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_rfp.email.owner.provider:
        class: Oro\Bundle\RFPBundle\Entity\Provider\EmailOwnerProvider
        tags:
            - { name: oro_email.owner.provider, order: 5}

    oro_rfp.updater.customer_user_reassign.request_updater:
        parent: oro_customer.updater.customer_user_reassign.abstract
        calls:
            - [ setEntityClass, [ 'Oro\Bundle\RFPBundle\Entity\Request' ] ]
        tags:
            - { name: oro_customer.updater.customer_user_reassign }

    oro_rfp.product_kit.provider.product_kit_item_products:
        class: Oro\Bundle\ProductBundle\ProductKit\Provider\ProductKitItemProductsProvider
        arguments:
            - '@oro_rfp.product_kit.checker.product_kit_item_product_availability_checker'

    oro_rfp.product_kit.checker.product_kit_item_product_availability_checker:
        class: Oro\Bundle\ProductBundle\ProductKit\Checker\ProductKitItemProductAvailabilityChecker
        arguments:
            - '@validator'
            - ['product_kit_item_product_is_available_for_rfp']

    oro_rfp.product_kit.factory.request_product_kit_item_line_item:
        class: Oro\Bundle\RFPBundle\ProductKit\Factory\RequestProductKitItemLineItemFactory
        arguments:
            - '@oro_rfp.product_kit.provider.product_kit_item_products'

    oro_rfp.autocomplete.product_visibility_limited.search_handler:
        parent: oro_product.autocomplete.product_visibility_limited.search_handler
        calls:
            - setNotAllowedProductTypes:
                  -
                      - !php/const Oro\Bundle\ProductBundle\Entity\Product::TYPE_CONFIGURABLE
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: oro_rfp_product_visibility_limited }

    oro_rfp.product_kit.checksum.request_product_kit_item_checksum_generator:
        class: Oro\Bundle\RFPBundle\ProductKit\Checksum\RequestProductKitItemChecksumGenerator
        tags:
            -
                name: oro_product.line_item_checksum_generator
                priority: 10 # Must be called before the default one - oro_product.product_kit.checksum.product_kit_line_item_checksum_generator

    oro_rfp.provider.request_product_price:
        class: Oro\Bundle\RFPBundle\Provider\RequestProductPriceProvider
        arguments:
            - '@oro_pricing.provider.product_price'
            - '@oro_pricing.model.product_price_scope_criteria_factory'
            - '@oro_pricing.user_currency_manager'

    oro_rfp.provider.request_product_line_item_tier_prices:
        class: Oro\Bundle\RFPBundle\Provider\RequestProductLineItemTierPricesProvider
        arguments:
            - '@oro_rfp.provider.request_product_price'
            - '@oro_pricing.provider.product_line_item_product_price'
            - '@oro_pricing.user_currency_manager'
