services:
    oro_notification.entity_spool:
        class: Oro\Bundle\NotificationBundle\Doctrine\EntityPool

    oro_notification.form.type.email_notification:
        class: Oro\Bundle\NotificationBundle\Form\Type\EmailNotificationType
        arguments:
            - '@oro_email.form.subscriber.emailtemplate'
            - '@oro_notification.form.subscriber.additional_emails'
            - '@router'
            - '@oro_notification.form.subscriber.contact_information_emails'
            - '%oro_notification.events%'
        tags:
            - { name: form.type, alias: emailnotification }

    oro_notification.form.type.recipient_list:
        class: Oro\Bundle\NotificationBundle\Form\Type\RecipientListType
        tags:
            - { name: form.type, alias: oro_notification_recipient_list }

    oro_notification.form.handler.email_notification:
        class: Oro\Bundle\NotificationBundle\Form\Handler\EmailNotificationHandler
        arguments:
            - '@doctrine'
        tags:
            - { name: oro_form.form.handler, alias: oro_notification.form.handler.email_notification }

    oro_notification.form.type.email_notification_entity_choice:
        class: Oro\Bundle\NotificationBundle\Form\Type\EmailNotificationEntityChoiceType
        arguments:
            - '@oro_notification.email_notification_entity_provider'
        tags:
            - { name: form.type, alias: oro_email_notification_entity_choice }

    oro_notification.form.subscriber.additional_emails:
        class: Oro\Bundle\NotificationBundle\Form\EventListener\AdditionalEmailsSubscriber
        arguments:
            - '@oro_notification.additional_email_association_provider'

    oro_notification.additional_email_association_provider:
        class: Oro\Bundle\NotificationBundle\Provider\ChainAdditionalEmailAssociationProvider
        arguments:
            - !tagged_iterator oro_notification.additional_email_association_provider

    oro_notification.additional_email_association_provider.default:
        class: Oro\Bundle\NotificationBundle\Provider\AdditionalEmailAssociationProvider
        arguments:
            - '@doctrine'
            - '@oro_entity_config.provider.entity'
            - '@translator'
        tags:
            - { name: oro_notification.additional_email_association_provider, priority: -100 }

    oro_notification.email_notification.manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\NotificationBundle\Entity\EmailNotification'
            - '@doctrine.orm.entity_manager'

    oro_notification.doctrine.event.listener:
        class: Oro\Bundle\NotificationBundle\Provider\DoctrineListener
        arguments:
            - '@oro_notification.entity_spool'
            - '@event_dispatcher'
        tags:
            - { name: doctrine.event_listener, event: postPersist }
            - { name: doctrine.event_listener, event: postUpdate }
            - { name: doctrine.event_listener, event: postRemove }
            - { name: doctrine.event_listener, event: postFlush }

    oro_notification.manager:
        class: Oro\Bundle\NotificationBundle\Provider\NotificationManager
        arguments:
            - !tagged_iterator notification.handler
            - '@oro_notification.cache'
            - '@doctrine'

    oro_notification.cache:
        parent: oro.data.cache
        tags:
            - { name: 'cache.pool', namespace: 'oro_notification' }

    oro_notification.event_listener.invalidate_cache_listener:
        class: Oro\Bundle\NotificationBundle\EventListener\InvalidateCacheListener
        arguments:
            - '@oro_notification.manager'
        tags:
            - { name: doctrine.event_listener, event: onFlush, priority: -255 }
            - { name: doctrine.event_listener, event: postFlush, priority: -255 }

    oro_notification.mass_notification_sender:
        class: Oro\Bundle\NotificationBundle\Model\MassNotificationSender
        arguments:
            - '@oro_notification.manager.email_notification'
            - '@oro_notification.model.notification_settings'
            - '@doctrine'
            - '@oro_notification.entity_spool'

    oro_notification.model.notification_settings:
        class: Oro\Bundle\NotificationBundle\Model\NotificationSettings
        arguments:
            - '@oro_config.manager'

    oro_notification.email_handler:
        class: Oro\Bundle\NotificationBundle\Event\Handler\EmailNotificationHandler
        arguments:
            - '@oro_notification.manager.email_notification'
            - '@doctrine'
            - '@property_accessor'
            - '@event_dispatcher'
            - '@oro_notification.additional_email_association_provider'
            - '@oro_notification.entity_website_aware_helper'
        tags:
            - { name: notification.handler, alias: email_notification_handler }

    oro_notification.grid_helper:
        class: Oro\Bundle\NotificationBundle\Provider\EmailNotificationGridHelper
        public: true
        arguments:
            - '@doctrine'
            - '%oro_notification.events%'

    oro_notification.email_notification_entity_provider:
        class: Oro\Bundle\NotificationBundle\Provider\EmailNotificationEntityProvider
        parent: oro_entity.entity_provider.abstract
        lazy: true
        arguments:
            - '@doctrine'

    oro_notification.event_listener.mass_notification_log:
        class: Oro\Bundle\NotificationBundle\EventListener\MassNotificationListener
        arguments:
            - '@doctrine'
        tags:
            - { name: kernel.event_listener, event: Oro\Bundle\NotificationBundle\Event\NotificationSentEvent, method: logMassNotification}

    oro_notification.mailer.mass_notifications:
        class: Oro\Bundle\NotificationBundle\Mailer\MassNotificationsMailer
        arguments:
            - '@mailer.transports'
            - '@event_dispatcher'

    oro_notification.async.send_email_notification_template_processor:
        class: Oro\Bundle\NotificationBundle\Async\SendEmailNotificationTemplateProcessor
        arguments:
            - '@doctrine'
            - '@oro_email.manager.template_email'
        calls:
            - [setLogger, ['@logger']]
        tags:
            - { name: 'oro_message_queue.client.message_processor', topicName: oro.notification.send_notification_email_template }

    oro_notification.async.send_email_notification_processor:
        class: Oro\Bundle\NotificationBundle\Async\SendEmailNotificationProcessor
        arguments:
            - '@mailer'
            - '@oro_email.embedded_images.handler.symfony_email'
        calls:
            - [setLogger, ['@logger']]
        tags:
            - { name: 'oro_message_queue.client.message_processor', topicName: oro.notification.send_notification_email }

    oro_notification.async.send_mass_email_notification_processor:
        class: Oro\Bundle\NotificationBundle\Async\SendEmailNotificationProcessor
        arguments:
            - '@oro_notification.mailer.mass_notifications'
            - '@oro_email.embedded_images.handler.symfony_email'
        calls:
            - [setLogger, ['@logger']]
        tags:
            - { name: 'oro_message_queue.client.message_processor', topicName: oro.notification.send_mass_notification_email }

    oro_notification.manager.email_notification:
        class: Oro\Bundle\NotificationBundle\Manager\EmailNotificationManager
        arguments:
            - '@oro_notification.manager.email_notification_sender'
            - '@logger'
            - '@oro_email.provider.localized_template'
        calls:
            - [setNotificationSettings, ['@oro_notification.model.notification_settings']]

    oro_notification.manager.email_notification_sender:
        class: Oro\Bundle\NotificationBundle\Manager\EmailNotificationSender
        arguments:
            - '@oro_notification.model.notification_settings'
            - '@oro_message_queue.client.message_producer'

    oro_notification.provider.contact_information_emails:
        class: Oro\Bundle\NotificationBundle\Provider\ContactInformationEmailsProvider
        arguments:
            - '@oro_entity_config.config_manager'
            - '@translator'

    oro_notification.form.subscriber.contact_information_emails:
        class: Oro\Bundle\NotificationBundle\Form\EventListener\ContactInformationEmailsSubscriber
        arguments:
            - '@oro_notification.provider.contact_information_emails'

    oro_notification.provider.email_address_with_context_preferred_localization_provider:
        class: Oro\Bundle\NotificationBundle\Provider\EmailAddressWithContextPreferredLocalizationProvider
        arguments:
            - '@oro_locale.provider.preferred_localization_provider'
        tags:
            - { name: oro_locale.preferred_localization_provider }

    oro_notification.notification_alert.datagrid_view_list:
        class: Oro\Bundle\NotificationBundle\Datagrid\NotificationAlertViewList
        public: true
        arguments:
            - '@translator'

    oro_notification.entity_website_aware_helper:
        class: Oro\Bundle\NotificationBundle\Helper\WebsiteAwareEntityHelper
        arguments:
            - "@oro_entity_config.config_manager"

    Oro\Bundle\NotificationBundle\Helper\WebsiteAwareEntityHelper:
        alias: oro_notification.entity_website_aware_helper

    oro_notification.aware_entity_configuration:
        class: Oro\Bundle\NotificationBundle\EntityConfig\WebsiteAwareEntityConfiguration
        tags:
            - oro_entity_config.validation.entity_config
