<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <defaults public="true" />

        <service class="Shopware\Bundle\EsBackendBundle\EsBackendIndexer" id="shopware_es_backend.indexer">
            <argument id="Elasticsearch\Client" type="service"/>
            <argument type="tagged" tag="shopware_es_backend.repository" />
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Console\EvaluationHelperInterface"/>
            <argument type="service" id="Shopware\Bundle\EsBackendBundle\IndexFactoryInterface"/>
        </service>

        <service id="Shopware\Bundle\EsBackendBundle\IndexFactoryInterface" class="Shopware\Bundle\EsBackendBundle\IndexFactory">
            <argument>%shopware.es.backend.prefix%</argument>
            <argument>%shopware.es.index_settings%</argument>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\SearchQueryBuilder" id="shopware_es_backend.search_query_builder" />

        <service class="Shopware\Bundle\EsBackendBundle\Searcher\OrderSearcher"
                 id="shopware_es_backend.order_searcher"
                 decorates="shopware_attribute.order_searcher">

            <argument id="Elasticsearch\Client" type="service"/>
            <argument id="shopware_es_backend.order_searcher.inner" type="service"/>
            <argument type="service" id="shopware_es_backend.search_query_builder"/>
            <argument>orders</argument>
            <argument>%shopware.es.backend.enabled%</argument>
            <argument type="service" id="Shopware\Bundle\EsBackendBundle\IndexFactoryInterface"/>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\Searcher\ProductSearcher"
                 id="shopware_es_backend.product_searcher"
                 decorates="shopware_attribute.product_searcher">

            <argument type="service" id="Elasticsearch\Client"/>
            <argument type="service" id="shopware_es_backend.product_searcher.inner"/>
            <argument type="service" id="shopware_es_backend.search_query_builder"/>
            <argument>product</argument>
            <argument>%shopware.es.backend.enabled%</argument>
            <argument type="service" id="Shopware\Bundle\EsBackendBundle\IndexFactoryInterface"/>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\Searcher\CustomerSearcher"
                 id="shopware_es_backend.customer_searcher"
                 decorates="shopware_attribute.customer_searcher">

            <argument type="service" id="Elasticsearch\Client"/>
            <argument type="service" id="shopware_es_backend.customer_searcher.inner"/>
            <argument type="service" id="shopware_es_backend.search_query_builder"/>
            <argument>customer</argument>
            <argument>%shopware.es.backend.enabled%</argument>
            <argument type="service" id="Shopware\Bundle\EsBackendBundle\IndexFactoryInterface"/>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\Subscriber\OrmBacklogSubscriber"
                 id="shopware_bundle.es_backend_subscriber.orm_backlog_subscriber">
            <argument type="service" id="service_container"/>

            <tag name="doctrine.event_subscriber"/>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\Subscriber\DomainBacklogSubscriber" id="shopware_bundle_es_backend.subscriber.domain_backlog_subscriber">
            <argument>%shopware.es.backend.write_backlog%</argument>
            <argument id="shopware_bundle_es_backend.backlog_service" type="service"/>

            <tag name="shopware.event_subscriber"/>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\BacklogService" id="shopware_bundle_es_backend.backlog_service">
            <argument id="Doctrine\DBAL\Connection" type="service"/>
        </service>

        <!-- Commands -->
        <service class="Shopware\Bundle\EsBackendBundle\Commands\IndexPopulateCommand"
                 id="shopware_es_backend.commands.index_populate_command">
            <tag name="console.command" command="sw:es:backend:index:populate"/>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\Commands\SyncBacklogCommand"
                 id="shopware_es_backend.commands.sync_backlog_command">
            <argument>%shopware.es.backend.batch_size%</argument>
            <argument type="service" id="Shopware\Bundle\EsBackendBundle\IndexFactoryInterface"/>

            <tag name="console.command" command="sw:es:backend:backlog:sync"/>
            <tag name="console.command" command="sw:es:backend:sync"/>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\Commands\IndexCleanupCommand"
                 id="shopware_es_backend.commands.index_cleanup_command">
            <tag name="console.command" command="sw:es:backend:index:cleanup"/>
        </service>

        <service class="Shopware\Bundle\EsBackendBundle\Commands\ClearBacklogCommand"
                 id="shopware_bundle_es_backend.commands.clear_backlog_command">
            <tag name="console.command" command="sw:es:backend:backlog:clear"/>
            <tag name="console.command" command="sw:es:backend:clear"/>
        </service>
    </services>
</container>

