services:
    oro_inventory.service.fallback_fields_form_view:
        abstract: true
        arguments:
            - '@request_stack'
            - '@doctrine'
            - '@translator'
        calls:
            - [setFieldAclHelper, ['@oro_security.form.field_acl_helper']]

    oro_inventory.listener.update_entity_config_relations:
        class: Oro\Bundle\InventoryBundle\CacheWarmer\UpdateEntityConfigRelationsWarmer
        arguments:
            - '@oro_inventory.entity_config_relations_migration'
        tags:
            - { name: oro_entity_extend.warmer, priority: -500 }

    oro_inventory.entity_config_relations_migration:
        class: Oro\Bundle\InventoryBundle\CacheWarmer\EntityConfigRelationsMigration
        arguments:
            - '@doctrine'
            - '@logger'
            - '@oro_distribution.handler.application_status'

    oro_inventory.validator.quantity_to_order_validator:
        class: Oro\Bundle\InventoryBundle\Validator\QuantityToOrderValidatorService
        arguments:
            - '@oro_entity.fallback.resolver.entity_fallback_resolver'
            - '@translator'
            - '@oro_entity.manager.preloading_manager'

    oro_inventory.validator.low_inventory_checkout_line_item_validator:
        class: Oro\Bundle\InventoryBundle\Validator\LowInventoryCheckoutLineItemValidator
        arguments:
            - '@oro_inventory.inventory.low_inventory_provider'
            - '@translator'

    oro_inventory.validator.upcoming_label_checkout_line_item_validator:
        class: Oro\Bundle\InventoryBundle\Validator\UpcomingLabelCheckoutLineItemValidator
        arguments:
            - '@oro_inventory.provider.upcoming_product_provider'
            - '@translator'
            - '@oro_locale.formatter.date_time'

    oro_inventory.validator.product_quantity_to_order_limit_validator:
        class: Oro\Bundle\InventoryBundle\Validator\Constraints\ProductQuantityToOrderLimitValidator
        arguments:
            - '@oro_inventory.validator.quantity_to_order_validator'
        tags:
            - { name: validator.constraint_validator }

    oro_inventory.validator.checkout_ship_until_validator:
        class: Oro\Bundle\InventoryBundle\Validator\Constraints\CheckoutShipUntilValidator
        arguments:
            - '@oro_inventory.provider.upcoming_product_provider'
            - '@oro_checkout.data_provider.manager.checkout_line_items'
        tags:
            - { name: validator.constraint_validator }

    oro_inventory.manager.inventory_quantity_manager:
        class: Oro\Bundle\InventoryBundle\Inventory\InventoryQuantityManager
        arguments:
            - '@oro_entity.fallback.resolver.entity_fallback_resolver'

    oro_inventory.handler.inventory_decrement_status_handler:
        class: Oro\Bundle\InventoryBundle\Inventory\InventoryStatusHandler
        arguments:
            - '@oro_entity.fallback.resolver.entity_fallback_resolver'
            - '@oro_entity.doctrine_helper'

    oro_inventory.manager.inventory_manager:
        class: Oro\Bundle\InventoryBundle\Inventory\InventoryManager
        public: true
        arguments:
            - '@oro_entity.doctrine_helper'

    oro_inventory.provider.inventory_quantity:
        class: Oro\Bundle\InventoryBundle\Provider\InventoryQuantityProvider
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_inventory.manager.inventory_quantity_manager'

    oro_inventory.product_manage_inventory.widget_provider.actions:
        parent: oro_ui.widget_provider.action_button.abstract
        arguments:
            - oro_product_manage_inventory_button
            - oro_product_manage_inventory_link
        tags:
            - { name: oro_ui.view_action_provider, group: activity, priority: -100 }

    oro_inventory.inventory.low_inventory_provider:
        class: Oro\Bundle\InventoryBundle\Inventory\LowInventoryProvider
        arguments:
            - '@oro_entity.fallback.resolver.entity_fallback_resolver'
            - '@doctrine'
        tags:
            - { name: layout.data_provider, alias: low_inventory }

    oro_inventory.provider.upcoming_product_provider:
        class: Oro\Bundle\InventoryBundle\Provider\UpcomingProductProvider
        arguments:
             - '@oro_entity.fallback.resolver.entity_fallback_resolver'
             - '@doctrine'
             - '@oro_config.manager'
             - '@property_accessor'
        tags:
            - { name: layout.data_provider, alias: upcoming_product }

    oro_inventory.twig.inventory_extension:
        class: Oro\Bundle\InventoryBundle\Twig\InventoryExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_inventory.event_listener.frontend_website_search_index:
        class: Oro\Bundle\InventoryBundle\EventListener\Frontend\WebsiteSearchProductIndexerListener
        arguments:
            - '@oro_entity.fallback.resolver.entity_fallback_resolver'
            - '@oro_inventory.provider.upcoming_product_provider'
        tags:
            - { name: kernel.event_listener, event: oro_website_search.event.index_entity.product, method: onWebsiteSearchIndex, priority: -200 }

    oro_inventory.event_listener.frontend_product_datagrid_low_inventory:
        class: Oro\Bundle\InventoryBundle\EventListener\Frontend\ProductDatagridLowInventoryListener
        arguments:
            - '@oro_inventory.inventory.low_inventory_provider'
            - '@doctrine'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.pre.frontend-product-search-grid, method: onPreBuild }
            - { name: kernel.event_listener, event: oro_datagrid.search_datasource.result.after.frontend-product-search-grid, method: onResultAfter }

    oro_inventory.event_listener.frontend_product_datagrid_upcoming_label:
        class: Oro\Bundle\InventoryBundle\EventListener\Frontend\ProductDatagridUpcomingLabelListener
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.pre.frontend-product-search-grid, method: onPreBuild }
            - { name: kernel.event_listener, event: oro_datagrid.search_datasource.result.after.frontend-product-search-grid, method: onResultAfter }

    oro_inventory.event_listener.product_list.low_inventory:
        class: Oro\Bundle\InventoryBundle\EventListener\Frontend\ProductListLowInventoryListener
        arguments:
            - '@oro_inventory.inventory.low_inventory_provider'
            - '@doctrine'
        tags:
            - { name: kernel.event_listener, event: oro_product.product_list.build_query, method: onBuildQuery }
            - { name: kernel.event_listener, event: oro_product.product_list.build_result, method: onBuildResult }

    oro_inventory.event_listener.product_list.upcoming_label:
        class: Oro\Bundle\InventoryBundle\EventListener\Frontend\ProductListUpcomingLabelListener
        tags:
            - { name: kernel.event_listener, event: oro_product.product_list.build_query, method: onBuildQuery }
            - { name: kernel.event_listener, event: oro_product.product_list.build_result, method: onBuildResult }

    oro_inventory.event_listener.product_duplicate:
        class: Oro\Bundle\InventoryBundle\EventListener\ProductDuplicateListener
        arguments:
            - '@property_accessor'
            -
                - 'manageInventory'
                - 'highlightLowInventory'
                - 'inventoryThreshold'
                - 'lowInventoryThreshold'
                - 'minimumQuantityToOrder'
                - 'maximumQuantityToOrder'
                - 'decrementQuantity'
                - 'backOrder'
                - 'isUpcoming'
        calls:
            - [setDoctrineHelper, ['@oro_entity.doctrine_helper']]
        tags:
            - { name: kernel.event_listener, event: oro_product.product.duplicate.after, method: onDuplicateAfter }

    oro_inventory.acl.access_rule.inventory_level:
        class: Oro\Bundle\InventoryBundle\Acl\AccessRule\InventoryLevelAccessRule
        tags:
            -
                name: oro_security.access_rule
                type: ORM
                permission: VIEW
                entityClass: Oro\Bundle\InventoryBundle\Entity\InventoryLevel
                loggedUserClass: Oro\Bundle\UserBundle\Entity\User

    Oro\Bundle\InventoryBundle\Validator\Constraints\QuantityToOrderValidator:
        arguments:
            - '@oro_inventory.validator.quantity_to_order_validator'
        tags:
            - { name: validator.constraint_validator }
