services:
    oro_organization.business_unit.manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\OrganizationBundle\Entity\BusinessUnit'
            - '@doctrine.orm.entity_manager'

    oro_organization.business_unit_manager:
        class: Oro\Bundle\OrganizationBundle\Entity\Manager\BusinessUnitManager
        public: true
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@oro_security.token_accessor'
            - '@oro_security.acl_helper'

    oro_organization.organization_manager:
        class: Oro\Bundle\OrganizationBundle\Entity\Manager\OrganizationManager
        public: true
        arguments:
            - '@doctrine'

    oro_organization.organization.manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\OrganizationBundle\Entity\Organization'
            - '@doctrine.orm.entity_manager'

    oro_organization.form.type.ownership_type:
        class: Oro\Bundle\OrganizationBundle\Form\Type\OwnershipType
        public: true
        tags:
            - { name: form.type, alias: oro_type_choice_ownership_type }

    Oro\Bundle\OrganizationBundle\Form\Type\OwnershipType:
        alias: oro_organization.form.type.ownership_type

    oro_organization.owner_assignment_checker.default:
        class: Oro\Bundle\OrganizationBundle\Ownership\OwnerAssignmentChecker
        tags:
            - { name: oro_organization.owner_assignment_checker, entity: default }

    oro_organization.owner_deletion_manager:
        class: Oro\Bundle\OrganizationBundle\Ownership\OwnerDeletionManager
        arguments:
            - !abstract '$checkerContainer defined in Oro\Bundle\OrganizationBundle\DependencyInjection\Compiler\OwnerDeletionManagerPass'
            - '@oro_entity_config.provider.ownership'
            - '@oro_security.owner.ownership_metadata_provider'
            - '@oro_entity.doctrine_helper'
            - '@oro_security.acl.object_id_accessor'

    oro_organization.entity_ownership_associations_setter:
        class: Oro\Bundle\OrganizationBundle\Ownership\EntityOwnershipAssociationsSetter
        arguments:
            - '@property_accessor'
            - '@oro_security.token_accessor'
            - '@oro_security.owner.ownership_metadata_provider'

    oro_organization.twig.organization_extension:
        class: Oro\Bundle\OrganizationBundle\Twig\OrganizationExtension
        public: false
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_organization.entity_ownership.listener:
        class: Oro\Bundle\OrganizationBundle\EventListener\RecordOwnerDataListener
        arguments:
            - '@oro_organization.entity_ownership_associations_setter'
        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\Bundle\OrganizationBundle\Event\ImportStrategyListener
        arguments:
            - '@doctrine'
            - '@oro_security.token_accessor'
            - '@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 }

    oro_organization.provider.business_units_grid:
        class: Oro\Bundle\OrganizationBundle\Provider\BusinessUnitGridService
        public: true
        arguments:
            - '@doctrine.orm.entity_manager'

    oro_organization.filter.business_unit:
        class: Oro\Bundle\OrganizationBundle\Filter\BusinessUnitChoiceFilter
        public: false
        arguments:
            - '@form.factory'
            - '@oro_filter.filter_utility'
            - '@router'
            - '@event_dispatcher'
            - '@doctrine'
        tags:
            - { name: oro_filter.extension.orm_filter.filter, type: choice-business-unit }

    oro_organization.entity_config_dumper.extension:
        class: Oro\Bundle\OrganizationBundle\Tools\OwnershipEntityConfigDumperExtension
        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\Bundle\OrganizationBundle\Event\BusinessUnitGridListener
        arguments:
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
            - '@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 }

    oro_organization.autocomplete.organization_search_handler:
        class: Oro\Bundle\OrganizationBundle\Autocomplete\OrganizationSearchHandler
        arguments:
            - 'Oro\Bundle\OrganizationBundle\Entity\Organization'
            - ['id', 'name']
            - ['name']
            - '@doctrine'
            - '@oro_security.token_accessor'
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: user_organizations }

    oro_organization.provider.phone.business_unit:
        class: Oro\Bundle\OrganizationBundle\Provider\BusinessUnitPhoneProvider
        tags:
            - { name: oro_address.phone_provider, class: 'Oro\Bundle\OrganizationBundle\Entity\BusinessUnit' }

    oro_organization.orm.validator.organization_unique:
        class: Oro\Bundle\OrganizationBundle\Validator\Constraints\OrganizationUniqueEntityValidator
        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\Bundle\OrganizationBundle\Provider\Filter\ChoiceTreeBusinessUnitProvider
        arguments:
            - '@doctrine'
            - '@oro_security.token_accessor'
            - '@oro_security.acl_helper'
            - '@oro_security.ownership_tree_provider.chain'

    oro_organization.autocomplete.business_unit.search_handler:
        class: Oro\Bundle\FormBundle\Autocomplete\SearchHandler
        parent: oro_form.autocomplete.search_handler
        arguments:
            - 'Oro\Bundle\OrganizationBundle\Entity\BusinessUnit'
            - ['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\Bundle\OrganizationBundle\Entity\BusinessUnit'
            - ['name']
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: widget_owner_business_units, acl_resource: oro_business_unit_view }

    oro_organization.delete_handler_extension.business_unit:
        class: Oro\Bundle\OrganizationBundle\Handler\BusinessUnitDeleteHandlerExtension
        parent: oro_entity.delete_handler_extension
        arguments:
            - '@oro_organization.owner_deletion_manager'
        tags:
            - { name: oro_entity.delete_handler_extension, entity: Oro\Bundle\OrganizationBundle\Entity\BusinessUnit }

    oro_organization.delete_handler_extension.organization:
        class: Oro\Bundle\OrganizationBundle\Handler\OrganizationDeleteHandlerExtension
        parent: oro_entity.delete_handler_extension
        arguments:
            - '@oro_organization.owner_deletion_manager'
        tags:
            - { name: oro_entity.delete_handler_extension, entity: Oro\Bundle\OrganizationBundle\Entity\Organization }

    oro_organization.organization_restriction_provider:
        class: Oro\Bundle\OrganizationBundle\Provider\OrganizationRestrictionProvider
        arguments:
            - '@oro_security.token_accessor'

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

    oro_organization.provider.business_unit_acl:
        class: Oro\Bundle\OrganizationBundle\Provider\BusinessUnitAclProvider
        arguments:
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
            - '@security.acl.voter.basic_permissions'
            - '@oro_security.ownership_tree_provider'

    oro_organization.autocomplete.business_unit_owner_search_handler:
        class: Oro\Bundle\OrganizationBundle\Autocomplete\BusinessUnitOwnerSearchHandler
        parent: oro_form.autocomplete.search_handler
        arguments:
            - 'Oro\Bundle\OrganizationBundle\Entity\BusinessUnit'
            - ['name']
            - '@doctrine'
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: business_units_owner_search_handler }

    oro_organization.autocomplete.parent_business_unit_search_handler:
        class: Oro\Bundle\OrganizationBundle\Autocomplete\ParentBusinessUnitSearchHandler
        parent: oro_organization.autocomplete.business_unit_owner_search_handler
        calls:
            - [setOwnerTreeProvider, ['@oro_security.ownership_tree_provider']]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: parent-business-units }

    oro_organization.listener.choice_tree_filter_load_data_listener:
        class: Oro\Bundle\OrganizationBundle\EventListener\ChoiceTreeFilterLoadDataListener
        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\Bundle\OrganizationBundle\Autocomplete\BusinessUnitTreeSearchHandler
        parent: oro_organization.autocomplete.business_unit_owner_search_handler
        calls:
            - [setTokenAccessor, ['@oro_security.token_accessor']]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: business_units_tree_search_handler }

    oro_organization.scope_criteria_provider.organization:
        class: Oro\Bundle\OrganizationBundle\Provider\ScopeOrganizationCriteriaProvider
        public: false
        arguments:
            - "@security.token_storage"

    oro_organization.validator.parent_business_unit:
        class: Oro\Bundle\OrganizationBundle\Validator\Constraints\ParentBusinessUnitValidator
        arguments:
           - '@oro_security.ownership_tree_provider'
        tags:
            - { name: validator.constraint_validator, alias: parent_business_unit_validator }

    Oro\Bundle\OrganizationBundle\EntityConfig\OwnershipEntityConfiguration:
        tags:
            - oro_entity_config.validation.entity_config

    Oro\Bundle\OrganizationBundle\EntityConfig\OrganizationEntityConfiguration:
        tags:
            - oro_entity_config.validation.entity_config

    Oro\Bundle\OrganizationBundle\EntityConfig\GlobalOrganizationAwareConfiguration:
        tags:
            - oro_entity_config.validation.entity_config

    oro_organization.entity_global_organization_aware_helper:
        class: Oro\Bundle\OrganizationBundle\Model\GlobalOrganizationAwareEntityHelper
        arguments:
            - "@oro_entity_config.config_manager"
