parameters:
    oro_checkout.entity.checkout.class: Oro\Bundle\CheckoutBundle\Entity\Checkout
    oro_checkout.entity.checkout_source.class: Oro\Bundle\CheckoutBundle\Entity\CheckoutSource
    oro_checkout.entity.checkout_workflow_state.class: Oro\Bundle\CheckoutBundle\Entity\CheckoutWorkflowState

services:
    # Data Providers
    oro_checkout.data_provider.converter.checkout_line_items:
        class: 'Oro\Bundle\CheckoutBundle\DataProvider\Converter\CheckoutLineItemsConverter'
        public: false
        arguments:
            - '@property_accessor'

    oro_checkout.data_provider.manager.checkout_line_items:
        class: 'Oro\Bundle\CheckoutBundle\DataProvider\Manager\CheckoutLineItemsManager'
        public: false
        arguments:
            - '@oro_checkout.data_provider.converter.checkout_line_items'
            - '@oro_pricing.user_currency_manager'
            - '@oro_config.manager'

    oro_checkout.layout.data_provider.line_items_totals:
        class: 'Oro\Bundle\CheckoutBundle\Layout\DataProvider\LineItemsWithTotalsProvider'
        arguments:
            - '@oro_checkout.data_provider.manager.checkout_line_items'
            - '@oro_pricing.subtotal_processor.provider.subtotal_line_item'
        tags:
            - { name: layout.data_provider, alias: oro_checkout_line_items_totals }

    oro_checkout.layout.data_provider.totals:
        class: 'Oro\Bundle\CheckoutBundle\Layout\DataProvider\TotalsProvider'
        arguments:
            - '@oro_checkout.provider.checkout_totals'
        tags:
            - { name: layout.data_provider, alias: oro_checkout_totals }

    oro_checkout.layout.data_provider.transition_form:
        class: 'Oro\Bundle\CheckoutBundle\Layout\DataProvider\TransitionFormProvider'
        arguments:
            - '@form.factory'
        calls:
            - [setTransitionProvider, ['@oro_checkout.layout.data_provider.transition']]
        tags:
            - { name: layout.data_provider, alias: oro_checkout_transition_form }

    oro_checkout.layout.data_provider.checkout_steps:
        class: 'Oro\Bundle\CheckoutBundle\Layout\DataProvider\CheckoutStepsProvider'
        arguments:
            - '@oro_workflow.manager'
        tags:
            - { name: layout.data_provider, alias: oro_checkout_steps }

    oro_checkout.layout.data_provider.transition:
        class: 'Oro\Bundle\CheckoutBundle\Layout\DataProvider\TransitionProvider'
        arguments:
            - '@oro_workflow.manager'
        tags:
            - { name: layout.data_provider, alias: oro_checkout_transition }

    oro_checkout.model.action.get_order_line_items:
        class: 'Oro\Bundle\CheckoutBundle\Model\Action\GetOrderLineItems'
        arguments:
            - '@oro_action.context_accessor'
            - '@oro_checkout.data_provider.manager.checkout_line_items'
        tags:
            - { name: oro_workflow.action, alias: get_order_line_items }

    oro_checkout.layout.data_provider.shipping_context:
        class: 'Oro\Bundle\CheckoutBundle\Layout\DataProvider\CheckoutShippingContextProvider'
        arguments:
            - '@oro_checkout.factory.shipping_context_provider_factory'
        tags:
            - { name: layout.data_provider, alias: checkout_shipping_context }

    oro_checkout.model.action.start_checkout:
        class: 'Oro\Bundle\CheckoutBundle\Model\Action\StartCheckout'
        calls:
            - [setCheckoutClass, ['%oro_checkout.entity.checkout.class%']]
            - [setCheckoutRoute, ['oro_checkout_frontend_checkout']]
        arguments:
            - '@oro_action.context_accessor'
            - '@doctrine'
            - '@oro_website.manager'
            - '@oro_pricing.user_currency_manager'
            - '@security.token_storage'
            - '@property_accessor'
            - '@oro_action.action.redirect'
            - '@event_dispatcher'
            - '@oro_workflow.manager'
        tags:
            - { name: oro_action.action, alias: start_checkout }

    oro_checkout.expression.acl_granted:
        class: Oro\Bundle\CheckoutBundle\Expression\CheckRequest
        arguments:
            - '@request_stack'
        tags:
            - { name: oro_workflow.condition, alias: check_request }

    oro_checkout.twig.line_items:
        class: 'Oro\Bundle\CheckoutBundle\Twig\LineItemsExtension'
        public: false
        arguments:
            - '@oro_pricing.subtotal_processor.total_processor_provider'
            - '@oro_pricing.subtotal_processor.provider.subtotal_line_item'
        tags:
            - { name: twig.extension }

    oro_checkout.event_listener.checkout_entity:
        class: 'Oro\Bundle\CheckoutBundle\EventListener\CheckoutEntityListener'
        lazy: true
        arguments:
            - '@doctrine'
            - '@oro_pricing.user_currency_manager'
        calls:
            - [setCheckoutClassName, ['%oro_checkout.entity.checkout.class%']]
        tags:
            - {name: kernel.event_listener, event: oro_checkout.get_checkout_entity, method: onGetCheckoutEntity}
            - {name: kernel.event_listener, event: oro_checkout.create_checkout_entity, method: onCreateCheckoutEntity}

    oro_checkout.event_listener.resolve_payment_term:
        class: 'Oro\Bundle\CheckoutBundle\EventListener\ResolvePaymentTermListener'
        arguments:
            - '@request_stack'
            - '@event_dispatcher'
        tags:
            - { name: kernel.event_listener, event: oro_payment.resolve.payment_term, method: onResolvePaymentTerm }

    oro_checkout.event_listener.shopping_list:
        class: 'Oro\Bundle\CheckoutBundle\EventListener\ShoppingListListener'
        public: false
        arguments:
            - '@doctrine'
            - '%oro_checkout.entity.checkout.class%'
            - '%oro_checkout.entity.checkout_source.class%'
        tags:
            - { name: doctrine.orm.entity_listener, entity: '%oro_shopping_list.entity.shopping_list.class%', event: preRemove }

    oro_checkout.grid_totals_metadata.cache:
        public: false
        parent: oro.cache.abstract
        calls:
            - [ setNamespace, [ 'oro_checkout_grid_totals_metadata' ] ]

    oro_checkout.repository.checkout:
        class: 'Oro\Bundle\CheckoutBundle\Entity\Repository\CheckoutRepository'
        parent: oro_entity.abstract_repository
        arguments:
            - '%oro_checkout.entity.checkout.class%'

    oro_checkout.datagrid.checkout_grid_helper:
        class: Oro\Bundle\CheckoutBundle\Datagrid\CheckoutGridHelper
        arguments:
            - '@doctrine'
            - '@oro_query_designer.entity_field_provider'
            - '@oro_entity_config.provider.entity'

    oro_checkout.datagrid.checkout_grid_listener:
        class: Oro\Bundle\CheckoutBundle\Datagrid\CheckoutGridListener
        arguments:
            - '@oro_pricing.user_currency_manager'
            - '@oro_checkout.repository.checkout'
            - '@oro_pricing.subtotal_processor.total_processor_provider'
            - '@oro_entity.entity_name_resolver'
            - '@oro_checkout.grid_totals_metadata.cache'
            - '@oro_checkout.datagrid.checkout_grid_helper'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.frontend-checkouts-grid, method: onBuildBefore }
            - { name: kernel.event_listener, event: oro_datagrid.orm_datasource.result.after.frontend-checkouts-grid, method: onResultAfter }

    oro_checkout.datagrid.checkout_grid_column_filter:
        class: 'Oro\Bundle\CheckoutBundle\Datagrid\CheckoutGridAccountUserNameListener'
        arguments:
            - '@oro_account.security.account_user_provider'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.frontend-checkouts-grid, method: onBuildBefore }

    oro_checkout.workflow.condition.order_line_item_has_count:
        class: 'Oro\Bundle\CheckoutBundle\Model\Condition\OrderLineItemsHasCount'
        arguments:
            - '@oro_checkout.data_provider.manager.checkout_line_items'
        tags:
            - { name: oro_workflow.condition, alias: order_line_item_has_count }

    oro_checkout.layout.provider.open_orders_separate_page_config:
        class: 'Oro\Bundle\CheckoutBundle\Layout\DataProvider\OpenOrdersSeparatePageConfigProvider'
        arguments:
            - '@oro_config.manager'
        tags:
            - { name: layout.data_provider, alias: oro_checkout_separate_open_orders }

    oro_checkout.migration.post_up.listener:
        class: 'Oro\Bundle\CheckoutBundle\EventListener\PostUpMigrationListener'
        tags:
            - { name: kernel.event_listener, event: oro_migration.post_up, method: onPostUp, priority: -80 }

    oro_checkout.workflow_state.storage.checkout_state_diff_storage:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Storage\CheckoutDiffStorage'
        pablic: false
        arguments:
            - '@oro_entity.doctrine_helper'
            - '%oro_checkout.entity.checkout_workflow_state.class%'

    oro_checkout.workflow_state.manager.checkout_state_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Manager\CheckoutStateDiffManager'
        arguments:
            - '@oro_checkout.workflow_state.mapper.registry.checkout_state_diff'

    oro_checkout.workflow_state.mapper.registry.checkout_state_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\CheckoutStateDiffMapperRegistry'
        public: false

    oro_checkout.workflow_state.mapper.workflow_step:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\WorkflowStepMapper'
        arguments:
            - '@oro_checkout.workflow.manager.b2b_flow_checkout'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.ship_to_billing_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\ShipToBillingDiffMapper'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.billing_address_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\BillingAddressDiffMapper'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.shipping_address_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\ShippingAddressDiffMapper'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.payment_method_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\PaymentMethodDiffMapper'
        arguments:
            - '@oro_payment.payment_method.registry'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.total_amount_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\TotalAmountDiffMapper'
        arguments:
            - '@oro_pricing.subtotal_processor.total_processor_provider'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.ship_until_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\ShipUntilDiffMapper'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.po_number_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\PoNumberDiffMapper'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.customer_notes_diff:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\CustomerNotesDiffMapper'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.mapper.payment_method_enabled:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Mapper\PaymentMethodEnabledMapper'
        arguments:
            - '@oro_payment.payment_method.registry'
            - '@oro_payment.provider.payment_context'
        public: false
        tags:
            - { name: checkout.workflow_state.mapper }

    oro_checkout.workflow_state.action.get_checkout_state:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Action\GetCheckoutStateAction'
        arguments:
            - '@oro_action.context_accessor'
            - '@oro_checkout.workflow_state.storage.checkout_state_diff_storage'
        tags:
            - { name: oro_workflow.action, alias: get_checkout_state }

    oro_checkout.workflow_state.action.save_checkout_state:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Action\SaveCheckoutStateAction'
        arguments:
            - '@oro_action.context_accessor'
            - '@oro_checkout.workflow_state.storage.checkout_state_diff_storage'
        tags:
            - { name: oro_workflow.action, alias: save_checkout_state }

    oro_checkout.workflow_state.action.delete_checkout_state:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Action\DeleteCheckoutStateAction'
        arguments:
            - '@oro_action.context_accessor'
            - '@oro_checkout.workflow_state.storage.checkout_state_diff_storage'
        tags:
            - { name: oro_workflow.action, alias: delete_checkout_state }

    oro_checkout.workflow_state.action.generate_checkout_state_snapshot:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Action\GenerateCheckoutStateSnapshotAction'
        arguments:
            - '@oro_action.context_accessor'
            - '@oro_checkout.workflow_state.manager.checkout_state_diff'
        tags:
            - { name: oro_workflow.action, alias: generate_checkout_state_snapshot }

    oro_checkout.workflow_state.condition.check_checkout_states:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Condition\CheckCheckoutStates'
        arguments:
            - '@oro_checkout.workflow_state.manager.checkout_state_diff'
        tags:
            - { name: oro_workflow.condition, alias: check_checkout_states }
            - { name: oro_action.condition, alias: check_checkout_states }

    oro_checkout.workflow_state.handler.checkout_error:
        class: 'Oro\Bundle\CheckoutBundle\WorkflowState\Handler\CheckoutErrorHandler'
        arguments:
            - '@session.flash_bag'

    oro_checkout.workflow.manager.b2b_flow_checkout:
        parent: oro_workflow.abstract.workflow_aware_manager
        calls:
            - ['setWorkflowName', ['b2b_flow_checkout']]

    oro_checkout.entity_listener.remove_checkout_workflow_states:
        class: 'Oro\Bundle\CheckoutBundle\EventListener\RemoveCheckoutWorkflowStatesListener'
        arguments:
            - '@oro_entity.doctrine_helper'
            - '%oro_checkout.entity.checkout_workflow_state.class%'
        public: false
        tags:
            - { name: doctrine.orm.entity_listener, entity: '%oro_checkout.entity.checkout.class%', event: preRemove }

    oro_checkout.condition.has_applicable_shipping_methods:
        class: 'Oro\Bundle\CheckoutBundle\Condition\HasApplicableShippingMethods'
        arguments:
            - '@oro_shipping.shipping_method.registry'
            - '@oro_shipping.shipping_price.provider'
            - '@oro_checkout.factory.shipping_context_provider_factory'
        tags:
            - { name: oro_workflow.condition, alias: 'has_applicable_shipping_methods' }
            - { name: oro_action.condition, alias: 'has_applicable_shipping_methods' }

    oro_checkout.condition.shipping_method_supports:
        class: 'Oro\Bundle\CheckoutBundle\Condition\ShippingMethodSupports'
        arguments:
            - '@oro_shipping.shipping_price.provider'
            - '@oro_checkout.factory.shipping_context_provider_factory'
        tags:
            - { name: oro_workflow.condition, alias: 'shipping_method_supports' }
            - { name: oro_action.condition, alias: 'shipping_method_supports' }

    oro_checkout.provider.checkout_totals:
        class: 'Oro\Bundle\CheckoutBundle\Provider\CheckoutTotalsProvider'
        arguments:
            - '@oro_checkout.data_provider.manager.checkout_line_items'
            - '@oro_pricing.subtotal_processor.total_processor_provider'
            - '@oro_checkout.mapper.order_mapper'

    oro_checkout.action.default_shipping_method_setter:
        class: 'Oro\Bundle\CheckoutBundle\Action\DefaultShippingMethodSetter'
        arguments:
            - '@oro_checkout.factory.shipping_context_provider_factory'
            - '@oro_shipping.shipping_price.provider'

    oro_checkout.factory.shipping_context_provider_factory:
        class: 'Oro\Bundle\CheckoutBundle\Factory\ShippingContextProviderFactory'
        arguments:
            - '@oro_checkout.data_provider.manager.checkout_line_items'
            - '@oro_pricing.subtotal_processor.total_processor_provider'
            - '@oro_shipping.factory.shipping_context_factory'

    oro_checkout.provider.privilege_category_provider:
        class: 'Oro\Bundle\CheckoutBundle\Provider\PrivilegeCategoryProvider'
        tags:
            - { name: oro_user.privilege_category}

    oro_checkout.mapper.order_mapper:
        class: 'Oro\Bundle\CheckoutBundle\Mapper\OrderMapper'
        public: false
        arguments:
            - '@oro_entity.entity_field_provider'
            - '@property_accessor'

    oro_checkout.model.action.create_order:
        class: 'Oro\Bundle\CheckoutBundle\Model\Action\CreateOrder'
        arguments:
            - '@oro_action.context_accessor'
            - '@oro_checkout.mapper.order_mapper'
        tags:
            - { name: oro_workflow.action, alias: create_order }
            - { name: oro_action.action, alias: create_order }
