services:
    oro_campaign.campaign.form.type:
        class: Oro\Bundle\CampaignBundle\Form\Type\CampaignType
        tags:
            - { name: form.type, alias: oro_campaign_form }

    oro_campaign.campaign.form:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments:
            - "oro_campaign_form"
            - Oro\Bundle\CampaignBundle\Form\Type\CampaignType

    oro_campaign.email_campaign.form.type:
        class: Oro\Bundle\CampaignBundle\Form\Type\EmailCampaignType
        calls:
            - [addSubscriber,  ["@oro_campaign.form.subscriber.transport_settings"]]
        tags:
            - { name: form.type, alias: oro_email_campaign }
        arguments:
            - "@oro_campaign.email_transport.provider"

    oro_campaign.email_campaign.form:
        class: Symfony\Component\Form\Form
        factory: ['@form.factory', createNamed]
        arguments:
            - "oro_email_campaign"
            - Oro\Bundle\CampaignBundle\Form\Type\EmailCampaignType

    oro_campaign.campaign.manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\CampaignBundle\Entity\Campaign'
            - "@doctrine.orm.entity_manager"

    oro_campaign.email_campaign.manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\CampaignBundle\Entity\EmailCampaign'
            - "@doctrine.orm.entity_manager"

    oro_campaign.data_transformer.multi_line:
        class: Oro\Bundle\CampaignBundle\Model\Data\Transformer\MultiLineDataTransformer

    oro_campaign.form.autocomplete.campaign.search_handler:
        parent: oro_form.autocomplete.search_handler
        arguments:
            - 'Oro\Bundle\CampaignBundle\Entity\Campaign'
            - ['name']
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: campaigns, acl_resource: oro_campaign_view }

    oro_campaign.form.type.campaign_select:
        class: Oro\Bundle\CampaignBundle\Form\Type\CampaignSelectType
        tags:
            - { name: form.type, alias: "oro_campaign_select" }

    oro_campaign.form.type.email_transport_select:
        class: Oro\Bundle\CampaignBundle\Form\Type\EmailTransportSelectType
        arguments:
            - "@oro_campaign.email_transport.provider"
        tags:
            - { name: form.type, alias: "oro_campaign_email_transport_select" }

    oro_campaign.transport.email:
        class: Oro\Bundle\CampaignBundle\Transport\EmailTransport
        arguments:
            - "@oro_email.sender.email_model_sender"
            - "@oro_email.email_renderer"
            - "@oro_entity.doctrine_helper"
            - "@oro_email.email.address.helper"
        calls:
            - [setLogger, ['@logger']]
        tags:
            - { name: "oro_campaign.email_transport" }

    oro_campaign.email_campaign.statistics_connector:
        class: Oro\Bundle\CampaignBundle\Model\EmailCampaignStatisticsConnector
        arguments:
            - "@oro_marketing_list.model.marketing_list_item_connector"
            - "@oro_entity.doctrine_helper"
        calls:
            - [setEntityName, ['Oro\Bundle\CampaignBundle\Entity\EmailCampaignStatistics']]

    oro_campaign.email_campaign.sender:
        class: Oro\Bundle\CampaignBundle\Model\EmailCampaignSender
        arguments:
            - "@oro_marketing_list.provider.marketing_list"
            - "@oro_config.user"
            - "@oro_campaign.email_campaign.statistics_connector"
            - "@oro_marketing_list.provider.contact_information_fields"
            - "@doctrine"
            - "@oro_campaign.email_transport.provider"
        calls:
            - [setLogger,  ["@logger"]]
            - [setValidator,  ["@validator"]]

    oro_campaign.email_transport.provider:
        class: Oro\Bundle\CampaignBundle\Provider\EmailTransportProvider

    oro_campaign.email_campaign.sender.builder:
        class: Oro\Bundle\CampaignBundle\Model\EmailCampaignSenderBuilder
        arguments:
            - "@oro_campaign.email_campaign.sender"

    Oro\Bundle\CampaignBundle\Model\EmailCampaignSenderBuilder:
        alias: oro_campaign.email_campaign.sender.builder

    oro_campaign.listener.email_campaign_statistic:
        class: Oro\Bundle\CampaignBundle\EventListener\CampaignStatisticDatagridListener
        arguments:
            - "@oro_marketing_list.model.helper"
            - "@doctrine"
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.pre, method: onPreBuild, priority: 300 }

    oro_campaign.listener.email_campaign_statistic_groupping:
        class: Oro\Bundle\CampaignBundle\EventListener\CampaignStatisticGroupingListener
        arguments:
            - "@oro_marketing_list.model.helper"
            - "@oro_campaign.group_by_helper"
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.pre, method: onPreBuild, priority: -10 }

    oro_campaign.listener.email_campaign_statistic_connector.cache_clear:
        class: Oro\Bundle\CampaignBundle\EventListener\EmailCampaignStatisticConnectorCacheClearListener
        arguments:
            - "@oro_campaign.email_campaign.statistics_connector"
        tags:
            - { name: doctrine.event_listener, event: onClear }

    oro_campaign.listener.campaign_code_history:
        class: Oro\Bundle\CampaignBundle\EventListener\CampaignCodeHistoryListener
        tags:
            - { name: doctrine.event_listener, event: onFlush }

    oro_campaign.form.type.internal_transport_settings:
        class: Oro\Bundle\CampaignBundle\Form\Type\InternalTransportSettingsType
        arguments:
            - "@doctrine"
        calls:
            - [addSubscriber,  ["@oro_campaign.form.subscriber.transport_settings_email_template"]]
        tags:
            - { name: form.type, alias: "oro_campaign_internal_transport_settings" }

    oro_campaign.form.subscriber.transport_settings:
        class: Oro\Bundle\CampaignBundle\Form\EventListener\TransportSettingsListener
        arguments:
            - "@oro_campaign.email_transport.provider"
            - "@oro_entity.doctrine_helper"

    oro_campaign.form.subscriber.transport_settings_email_template:
        class: Oro\Bundle\CampaignBundle\Form\EventListener\TransportSettingsEmailTemplateListener
        arguments:
            - "@doctrine"
            - "@oro_security.token_accessor"

    oro_campaign.group_by_helper:
        alias: oro_query_designer.group_by_helper

    oro_campaign.provider.tracking_identificator:
        class: Oro\Bundle\CampaignBundle\Provider\TrackingVisitEventIdentification
        arguments:
           - "@doctrine"
        tags:
           - {name: oro_tracking.provider.identification, priority: 10}

    oro_campaign.dashboard.campaign_data_provider:
        class: Oro\Bundle\CampaignBundle\Dashboard\CampaignDataProvider
        arguments:
            - '@doctrine'
            - '@oro_security.acl_helper'
            - '@oro_dashboard.filter.date_filter_processor'
            - '@oro_currency.query.currency_transformer'

    Oro\Bundle\CampaignBundle\Dashboard\CampaignDataProvider:
        alias: oro_campaign.dashboard.campaign_data_provider

    oro_campaign.validator.campaign_code:
        class: Oro\Bundle\CampaignBundle\Validator\Constraints\CampaignCodeValidator
        arguments:
            - '@doctrine'
        tags:
            - { name: validator.constraint_validator }

    oro_campaign.cron.calculate_tracking_event_summary_command_feature_checker:
        class: Oro\Bundle\CampaignBundle\Command\CalculateTrackingEventSummaryCommandFeatureChecker
        decorates: oro_cron.command_feature_checker
        arguments:
            - '@.inner'
            - '@oro_featuretoggle.checker.feature_checker'
