parameters:
    # Entity classes
    oro_notification.event_entity.class: Oro\Bundle\NotificationBundle\Entity\Event
    oro_notification.emailnotification.entity.class: Oro\Bundle\NotificationBundle\Entity\EmailNotification

    # Entity spool
    oro_notification.entity_spool.class: Oro\Bundle\NotificationBundle\Doctrine\EntityPool

    # Notification processors
    oro_notification.email_processor.class: Oro\Bundle\NotificationBundle\Processor\EmailNotificationProcessor

    # Event manager and event handler classes
    oro_notification.manager.class: Oro\Bundle\NotificationBundle\Provider\NotificationManager
    oro_notification.email_handler.class: Oro\Bundle\NotificationBundle\Event\Handler\EmailNotificationHandler

    # Listener classes
    oro_notification.doctrine_listener.class: Oro\Bundle\NotificationBundle\Provider\DoctrineListener

    # Email notification form services
    oro_notification.form.type.email_notification.class: Oro\Bundle\NotificationBundle\Form\Type\EmailNotificationType
    oro_notification.form.type.recipient_list.class: Oro\Bundle\NotificationBundle\Form\Type\RecipientListType
    oro_notification.form.handler.email_notification.class: Oro\Bundle\NotificationBundle\Form\Handler\EmailNotificationHandler
    oro_notification.form.type.email_notification_entity_choice.class: Oro\Bundle\NotificationBundle\Form\Type\EmailNotificationEntityChoiceType

    # Email notification API
    oro_notification.email_notification.manager.api.class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
    oro_notification.form.type.email_notification.api.class: Oro\Bundle\NotificationBundle\Form\Type\EmailNotificationApiType
    oro_notification.form.handler.email_notification.api.class: Oro\Bundle\NotificationBundle\Form\Handler\EmailNotificationHandler

    # Email notification services
    oro_notification.mailer.transport.spool_db.class: Oro\Bundle\NotificationBundle\Provider\Mailer\DbSpool
    oro_notification.mailer.transport.spool_entity.class: Oro\Bundle\NotificationBundle\Entity\SpoolItem

    swiftmailer.mailer.db_spool_mailer.spool.enabled: true

    oro_notification.event_listener.email_notification_service.class: Oro\Bundle\NotificationBundle\Provider\EmailNotificationGridHelper

    oro_notification.email_notification_entity_provider.class: Oro\Bundle\NotificationBundle\Provider\EmailNotificationEntityProvider

services:
    # Entity spool
    oro_notification.entity_spool:
        class: %oro_notification.entity_spool.class%

    # Email notification form services
    oro_notification.form.email_notification:
        class: Symfony\Component\Form\Form
        factory_method: createNamed
        factory_service: form.factory
        arguments: ["emailnotification", "emailnotification", null]

    oro_notification.form.type.email_notification:
        class: %oro_notification.form.type.email_notification.class%
        arguments:
            - @oro_email.form.subscriber.emailtemplate
            - @oro_entity_config.provider.ownership
        tags:
            - { name: form.type, alias: emailnotification }

    oro_notification.form.type.recipient_list:
        class: %oro_notification.form.type.recipient_list.class%
        arguments:
            - @doctrine.orm.entity_manager
        tags:
            - { name: form.type, alias: oro_notification_recipient_list }

    oro_notification.form.handler.email_notification:
        class: %oro_notification.form.handler.email_notification.class%
        scope: request
        arguments:
            - @oro_notification.form.email_notification
            - @request
            - @doctrine.orm.entity_manager

    oro_notification.form.type.email_notification_entity_choice:
        class: %oro_notification.form.type.email_notification_entity_choice.class%
        arguments:
            - @oro_notification.email_notification_entity_provider
        tags:
            - { name: form.type, alias: oro_email_notification_entity_choice }

    # Email notification API
    oro_notification.email_notification.manager.api:
        class: %oro_notification.email_notification.manager.api.class%
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - %oro_notification.emailnotification.entity.class%
            - @doctrine.orm.entity_manager

    oro_notification.form.type.email_notification.api:
        class: %oro_notification.form.type.email_notification.api.class%
        arguments:
            - @oro_email.form.subscriber.emailtemplate
            - @oro_entity_config.provider.ownership
        tags:
            - { name: form.type, alias: emailnotification_api }

    oro_notification.form.email_notification.api:
        class: Symfony\Component\Form\Form
        factory_method: createNamed
        factory_service: form.factory
        arguments: ["emailnotification_api", "emailnotification_api", null]

    oro_notification.form.handler.email_notification.api:
        class: %oro_notification.form.handler.email_notification.api.class%
        scope: request
        arguments:
            - @oro_notification.form.email_notification.api
            - @request
            - @doctrine.orm.entity_manager

    # Event listeners
    oro_notification.docrine.event.listener:
        class: %oro_notification.doctrine_listener.class%
        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 }

    # notification services
    oro_notification.manager:
        class: %oro_notification.manager.class%
        arguments:
            - @doctrine.orm.entity_manager
            - %oro_notification.emailnotification.entity.class%
        lazy: true

    oro_notification.email_processor:
        class: %oro_notification.email_processor.class%
        arguments:
            - @logger
            - @doctrine.orm.entity_manager
            - @oro_notification.entity_spool
            - @oro_email.email_renderer
            - @swiftmailer.mailer.db_spool_mailer
            - @oro_config.global
        calls:
            - [ setEnv, ['prod'] ]
            - [ setMessageLimit, [100] ]

    oro_notification.email_handler:
        class: %oro_notification.email_handler.class%
        arguments:
            - @oro_notification.email_processor
            - @doctrine.orm.entity_manager
            - @oro_entity_config.provider.ownership
        tags:
            - { name: notification.handler, alias: email_notification_handler }

    # email notification Swift mailer with DB spool configured
    oro_notification.mailer.spool_db:
        class: %oro_notification.mailer.transport.spool_db.class%
        arguments:
            - @doctrine.orm.entity_manager
            - @oro_notification.entity_spool
            - %oro_notification.mailer.transport.spool_entity.class%

    oro_notification.mailer.transport.eventdispatcher:
        parent: swiftmailer.transport.eventdispatcher.abstract

    oro_notification.mailer.transport:
        parent: swiftmailer.transport.spool.abstract
        arguments:
            - @oro_notification.mailer.transport.eventdispatcher
            - @oro_notification.mailer.spool_db

    # notification mailer instance
    swiftmailer.mailer.db_spool_mailer:
        class: %swiftmailer.class%
        arguments:
            - @oro_notification.mailer.transport

    swiftmailer.mailer.db_spool_mailer.transport.real:
        alias: swiftmailer.transport.real

    oro_notification.event_listener.email_notification_service:
        class: %oro_notification.event_listener.email_notification_service.class%
        arguments:
            - @doctrine.orm.entity_manager
        lazy: true

    oro_notification.email_notification_entity_provider:
        class: %oro_notification.email_notification_entity_provider.class%
        parent: oro_entity.entity_provider.abstract
        arguments:
            - @doctrine.orm.entity_manager
        lazy: true
