parameters:
    oro_organization.business_unit.entity.class:               Oro\Bundle\OrganizationBundle\Entity\BusinessUnit
    oro_organization.business_unit.manager.class:              Oro\Bundle\OrganizationBundle\Entity\Manager\BusinessUnitManager
    oro_organization.organization.manager.class:               Oro\Bundle\OrganizationBundle\Entity\Manager\OrganizationManager
    oro_organization.organization.entity.class:                Oro\Bundle\OrganizationBundle\Entity\Organization

    oro_organization.business_unit.manager.api.class:          Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
    oro_organization.organization.manager.api.class:           Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager

    oro_organization.twig.get_owner.class:                     Oro\Bundle\OrganizationBundle\Twig\OwnerTypeExtension
    oro_organization.twig.business_units.class:                Oro\Bundle\OrganizationBundle\Twig\BusinessUnitExtension

    oro_organization.form.listener.class:                      Oro\Bundle\OrganizationBundle\Event\FormListener
    oro_organization.entity_ownership.listener.class:          Oro\Bundle\OrganizationBundle\Event\RecordOwnerDataListener
    oro_organization.business_unit.listener.class:             Oro\Bundle\OrganizationBundle\Event\BusinessUnitListener
    oro_organization.import_strategy.listener.class:           Oro\Bundle\OrganizationBundle\Event\ImportStrategyListener
    oro_organization.listener.choice_tree_filter_load_data_listener.class: Oro\Bundle\OrganizationBundle\EventListener\ChoiceTreeFilterLoadDataListener

    oro_organization.provider.business_units.class:            Oro\Bundle\OrganizationBundle\Provider\BusinessUnitGridService

    oro_organization.owner_deletion_manager.class:             Oro\Bundle\OrganizationBundle\Ownership\OwnerDeletionManager
    oro_organization.owner_assignment_checker.default.class:   Oro\Bundle\OrganizationBundle\Ownership\OwnerAssignmentChecker

    oro_organization.entity_config_dumper.extension.class:     Oro\Bundle\OrganizationBundle\Tools\OwnershipEntityConfigDumperExtension

    oro_organization.event.business_unit_grid_listener.class:  Oro\Bundle\OrganizationBundle\Event\BusinessUnitGridListener

    oro_organization.autocomplete.organization_search_handler.class: Oro\Bundle\OrganizationBundle\Autocomplete\OrganizationSearchHandler

    oro_organization.provider.phone.business_unit.class:       Oro\Bundle\OrganizationBundle\Provider\BusinessUnitPhoneProvider

    oro_organization.orm.validator.oranization_unique.class:   Oro\Bundle\OrganizationBundle\Validator\Constraints\OrganizationUniqueEntityValidator
    oro_organization.provider.filter.busines_unit_choice_tree.class: Oro\Bundle\OrganizationBundle\Provider\Filter\ChoiceTreeBusinessUnitProvider

    oro_organization.autocomplete.business_unit.search_handler.class:  Oro\Bundle\FormBundle\Autocomplete\SearchHandler
    oro_organization.provider.busines_unit_acl.class: Oro\Bundle\OrganizationBundle\Provider\BusinessUnitAclProvider
    oro_organization.autocomplete.business_unit_owner_search_handler.class: Oro\Bundle\OrganizationBundle\Autocomplete\BusinessUnitOwnerSearchHandler
    oro_organization.autocomplete.business_unit_tree_search_handler.class: Oro\Bundle\OrganizationBundle\Autocomplete\BusinessUnitTreeSearchHandler

services:
    #
    # Business Unit API
    #
    oro_organization.business_unit.manager.api:
        class: %oro_organization.business_unit.manager.api.class%
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - %oro_organization.business_unit.entity.class%
            - '@doctrine.orm.entity_manager'

    oro_organization.business_unit_manager:
        class: %oro_organization.business_unit.manager.class%
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@oro_security.security_facade'
            - '@oro_security.acl_helper'

    oro_organization.organization_manager:
        class: %oro_organization.organization.manager.class%
        arguments:
            - '@doctrine.orm.entity_manager'

    #
    # Organization API
    #
    oro_organization.organization.manager.api:
        class: %oro_organization.organization.manager.api.class%
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - %oro_organization.organization.entity.class%
            - '@doctrine.orm.entity_manager'
    #
    # Ownership
    #
    oro_organization.form.type.ownership_type:
        class: %oro_organization.form.type.ownership_type.class%
        tags:
            - { name: form.type, alias: oro_type_choice_ownership_type }

    oro_organization.owner_assignment_checker.default:
        class: %oro_organization.owner_assignment_checker.default.class%
        public: false

    oro_organization.owner_deletion_manager:
        class: %oro_organization.owner_deletion_manager.class%
        arguments:
            - '@oro_organization.owner_assignment_checker.default'
            - '@oro_entity_config.provider.ownership'
            - '@oro_security.owner.ownership_metadata_provider'
            - '@doctrine.orm.entity_manager'
            - '@oro_security.acl.object_id_accessor'
        lazy: true
    #
    # Twig
    #
    oro_organization.twig.get_owner:
        class: %oro_organization.twig.get_owner.class%
        arguments:
            - '@oro_entity_config.provider.ownership'
            - '@oro_security.owner.entity_owner_accessor'
        tags:
            - { name: twig.extension }

    oro_organization.twig.business_units:
        class: %oro_organization.twig.business_units.class%
        arguments:
            - '@oro_organization.business_unit_manager'
        tags:
            - { name: twig.extension }

    oro_organization.link.security_context:
        tags:
            - { name: oro_service_link,  service: security.context }

    #
    # Listeners / Subscribers
    #
    oro_organization.entity_ownership.listener:
        class: %oro_organization.entity_ownership.listener.class%
        arguments: ["@oro_organization.link.security_context", "@oro_entity_config.provider.ownership"]
        tags:
             - { name: doctrine.event_listener, event: prePersist }

    oro_organization.listener.config_listener:
        class: Oro\Bundle\OrganizationBundle\Event\EntityConfigListener
        tags:
            - { name: kernel.event_listener, event: oro.entity_config.pre_flush, method: preFlush, priority: 100 }

    oro_organization.import_strategy.listener:
        class: %oro_organization.import_strategy.listener.class%
        arguments:
            - '@doctrine'
            - '@oro_security.security_facade.link'
            - '@oro_security.owner.ownership_metadata_provider.link'
        tags:
            - { name: kernel.event_listener, event: oro_importexport.strategy.process_after, method: onProcessAfter }
            - { name: doctrine.event_listener, event: onClear }

    #
    # DataGrid
    #
    oro_organization.provider.business_units_grid:
        class: %oro_organization.provider.business_units.class%
        arguments:
            - '@doctrine.orm.entity_manager'
    #
    # Entity config dumper extension
    #
    oro_organization.entity_config_dumper.extension:
        class: %oro_organization.entity_config_dumper.extension.class%
        arguments:
            - '@oro_entity_config.config_manager'
            - '@oro_entity_extend.relation_builder'
            - '@oro_security.owner.ownership_metadata_provider'
        tags:
            - { name: oro_entity_extend.entity_config_dumper_extension }

    oro_organization.event.business_unit_grid_listener:
        class: %oro_organization.event.business_unit_grid_listener.class%
        arguments:
            - '@oro_entity_config.link.security_context'
            - '@oro_security.ownership_tree_provider'
            - "@?security.acl.voter.basic_permissions"
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.business-unit-grid, method: onBuildBefore }

    # Autocomplete user organizations search handler
    oro_organization.autocomplete.organization_search_handler:
        class: %oro_organization.autocomplete.organization_search_handler.class%
        arguments:
            - %oro_organization.organization.entity.class%
            - ["id", "name"]
            - ["name"]
            - '@doctrine'
            - '@oro_entity_config.link.security_context'
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: user_organizations }
        lazy: true

    oro_organization.provider.phone.business_unit:
        class: %oro_organization.provider.phone.business_unit.class%
        tags:
            - { name: oro_address.phone_provider, class: %oro_organization.business_unit.entity.class% }

    oro_organization.orm.validator.organization_unique:
        class: %oro_organization.orm.validator.oranization_unique.class%
        arguments:
            - '@doctrine'
            - '@oro_security.owner.ownership_metadata_provider'
            - '@oro_entity.doctrine_helper'
        tags:
              - { name: validator.constraint_validator, alias: organization_unique }

    oro_organization.provider.filter.busines_unit_choice_tree:
        class: %oro_organization.provider.filter.busines_unit_choice_tree.class%
        arguments:
            - '@doctrine'
            - '@oro_security.security_facade'
            - '@oro_security.acl_helper'
            - '@oro_security.ownership_tree_provider.chain'

    oro_organization.autocomplete.business_unit.search_handler:
        class: %oro_organization.autocomplete.business_unit.search_handler.class%
        parent: oro_form.autocomplete.search_handler
        arguments:
            - %oro_organization.business_unit.entity.class%
            - ["name"]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: business_units, acl_resource: oro_business_unit_view }

    oro_organization.autocomplete.widget_business_unit.search_handler:
        class: Oro\Bundle\OrganizationBundle\Autocomplete\WidgetBusinessUnitSearchHandler
        parent: oro_form.autocomplete.search_handler
        arguments:
            - '@translator'
            - %oro_organization.business_unit.entity.class%
            - ["name"]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: widget_owner_business_units, acl_resource: oro_business_unit_view }

    oro_organization.business_unit.handler.delete:
        class: Oro\Bundle\OrganizationBundle\Handler\BusinessUnitDeleteHandler
        parent: oro_soap.handler.delete.abstract

    oro_organization.organization.handler.delete:
        class: Oro\Bundle\OrganizationBundle\Handler\OrganizationDeleteHandler
        parent: oro_soap.handler.delete.abstract

    oro_organization.validator.owner:
        class: Oro\Bundle\OrganizationBundle\Validator\Constraints\OwnerValidator
        arguments:
           - '@doctrine'
           - '@oro_organization.business_unit_manager'
           - '@oro_security.owner.ownership_metadata_provider'
           - '@oro_security.owner.entity_owner_accessor'
           - '@oro_security.security_facade'
           - '@oro_security.ownership_tree_provider'
           - '@?security.acl.voter.basic_permissions'
        tags:
            - { name: validator.constraint_validator, alias: owner_validator }

    oro_organization.provider.busines_unit_acl:
        class: %oro_organization.provider.busines_unit_acl.class%
        arguments:
            - '@oro_security.security_facade'
            - '@?security.acl.voter.basic_permissions'
            - '@oro_security.ownership_tree_provider'

    oro_organization.autocomplete.business_unit_owner_search_handler:
        class: '%oro_organization.autocomplete.business_unit_owner_search_handler.class%'
        parent: oro_form.autocomplete.search_handler
        arguments:
            - %oro_organization.business_unit.entity.class%
            - ["name"]
            - '@doctrine'
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: business_units_owner_search_handler }
        lazy: true

    oro_organization.listener.choice_tree_filter_load_data_listener:
        class: '%oro_organization.listener.choice_tree_filter_load_data_listener.class%'
        arguments:
            - '@doctrine'
        tags:
            - { name: kernel.event_listener, event: oro_filter.choice_tree_filter_load_data, method: fillData }

    oro_organization.autocomplete.business_unit_tree_search_handler:
        class: '%oro_organization.autocomplete.business_unit_tree_search_handler.class%'
        parent: oro_organization.autocomplete.business_unit_owner_search_handler
        calls:
            - [setSecurityFacade, ['@oro_security.security_facade']]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: business_units_tree_search_handler }
        lazy: true
