<?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 id="shopware_elastic_search.client" class="Elasticsearch\Client">
            <factory class="Shopware\Bundle\ESIndexingBundle\ClientFactory" method="createClient"/>
            <argument>%shopware.es.client%</argument>
            <argument type="service" id="eslogger"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Console\EvaluationHelperInterface"/>
            <deprecated>The "shopware_elastic_search.client.logger" service is deprecated. Use "%service_id%" instead</deprecated>
        </service>

        <service id="shopware_elastic_search.client.logger" alias="shopware_elastic_search.client"/>

        <service id="shopware_elastic_search.shop_indexer_factory"
                 class="Shopware\Bundle\ESIndexingBundle\DependencyInjection\Factory\ShopIndexerFactory">
            <argument type="tagged" tag="shopware_elastic_search.data_indexer"/>
            <argument type="tagged" tag="shopware_elastic_search.mapping"/>
            <argument type="tagged" tag="shopware_elastic_search.settings"/>
        </service>

        <service id="shopware_elastic_search.shop_indexer" class="Shopware\Bundle\ESIndexingBundle\ShopIndexer">
            <factory service="Shopware\Bundle\ESIndexingBundle\DependencyInjection\Factory\ShopIndexerFactory" method="factory"/>
            <argument type="service" id="service_container"/>
        </service>

        <service id="shopware_elastic_search.field_mapping" class="Shopware\Bundle\ESIndexingBundle\FieldMapping">
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\ShopAnalyzerInterface"/>
            <argument type="service" id="shopware_elastic_search.text_mapping"/>
        </service>

        <service id="shopware_elastic_search.text_mapping"
                 class="Shopware\Bundle\ESIndexingBundle\TextMappingInterface">
            <factory service="Shopware\Bundle\ESIndexingBundle\DependencyInjection\Factory\TextMappingFactory" method="factory"/>
            <argument type="service" id="Elasticsearch\Client"/>
        </service>

        <service id="shopware_elastic_search.text_mapping_factory" class="Shopware\Bundle\ESIndexingBundle\DependencyInjection\Factory\TextMappingFactory"/>

        <service id="shopware_elastic_search.index_factory" class="Shopware\Bundle\ESIndexingBundle\IndexFactory">
            <argument>%shopware.es.prefix%</argument>
            <argument>%shopware.es.index_settings%</argument>
        </service>

        <service id="shopware_elastic_search.shop_analyzer" class="Shopware\Bundle\ESIndexingBundle\ShopAnalyzer"/>

        <service id="shopware_elastic_search.product_query_factory"
                 class="Shopware\Bundle\ESIndexingBundle\Product\ProductQueryFactory">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="Shopware\Bundle\SearchBundleDBAL\VariantHelperInterface"/>
        </service>

        <service id="shopware_elastic_search.property_query_factory"
                 class="Shopware\Bundle\ESIndexingBundle\Property\PropertyQueryFactory">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
        </service>

        <service id="shopware_elastic_search.identifier_selector"
                 class="Shopware\Bundle\ESIndexingBundle\IdentifierSelector">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Gateway\ShopGatewayInterface"/>
        </service>

        <service id="shopware_elastic_search.backlog_processor"
                 class="Shopware\Bundle\ESIndexingBundle\BacklogProcessor">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="tagged" tag="shopware_elastic_search.synchronizer"/>
            <argument type="service" id="events"/>
        </service>

        <service id="shopware_elastic_search.backlog_reader" class="Shopware\Bundle\ESIndexingBundle\BacklogReader">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
        </service>

        <service id="shopware_elastic_search.property_indexer"
                 class="Shopware\Bundle\ESIndexingBundle\Property\PropertyIndexer">
            <argument type="service" id="Elasticsearch\Client"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Property\PropertyQueryFactory"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Property\PropertyProvider"/>

            <tag name="shopware_elastic_search.data_indexer"/>
        </service>

        <service id="shopware_elastic_search.property_synchronizer"
                 class="Shopware\Bundle\ESIndexingBundle\Property\PropertySynchronizer">
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Property\PropertyIndexer"/>

            <tag name="shopware_elastic_search.synchronizer"/>
        </service>

        <service id="shopware_elastic_search.property_provider"
                 class="Shopware\Bundle\ESIndexingBundle\Property\PropertyProvider">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\FieldHelper"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\Hydrator\PropertyHydrator"/>
        </service>

        <service id="shopware_elastic_search.property_mapping"
                 class="Shopware\Bundle\ESIndexingBundle\Property\PropertyMapping">
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\FieldMapping"/>
            <argument>%shopware.es.dynamic_mapping_enabled%</argument>

            <tag name="shopware_elastic_search.mapping"/>
        </service>

        <service id="shopware_elastic_search.product_indexer"
                 class="Shopware\Bundle\ESIndexingBundle\Product\ProductIndexer">
            <argument type="service" id="Elasticsearch\Client"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Product\ProductProvider"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Product\ProductQueryFactory"/>
            <argument type="service" id="Shopware\Bundle\SearchBundleDBAL\VariantHelperInterface"/>

            <tag name="shopware_elastic_search.data_indexer"/>
        </service>

        <service id="shopware_elastic_search.product_synchronizer"
                 class="Shopware\Bundle\ESIndexingBundle\Product\ProductSynchronizer">
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Product\ProductQueryFactory"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Product\ProductIndexer"/>

            <tag name="shopware_elastic_search.synchronizer"/>
        </service>

        <service id="shopware_elastic_search.product_provider"
                 class="Shopware\Bundle\ESIndexingBundle\Product\ProductProvider">
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Gateway\ListProductGatewayInterface"/>
            <argument type="service" id="shopware_storefront.cheapest_price_es_service"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Service\VoteServiceInterface"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface"/>
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\IdentifierSelector"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Service\PriceCalculationServiceInterface"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\FieldHelper"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\Hydrator\PropertyHydrator"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Service\ConfiguratorServiceInterface"/>
            <argument type="service" id="Shopware\Bundle\SearchBundleDBAL\VariantHelperInterface"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Product\ProductConfigurationLoader"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Product\ProductListingVariationLoader"/>
            <argument type="service" id="Shopware\Bundle\AttributeBundle\Service\CrudService"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Product\ProductManualPositionLoader"/>
            <argument type="service" id="config"/>
        </service>

        <service id="shopware_elastic_search.product_mapping"
                 class="Shopware\Bundle\ESIndexingBundle\Product\ProductMapping">
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\IdentifierSelector"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\FieldMapping"/>
            <argument type="service" id="shopware_elastic_search.text_mapping"/>
            <argument type="service" id="Shopware\Bundle\AttributeBundle\Service\CrudService"/>
            <argument type="service" id="Shopware\Bundle\SearchBundleDBAL\VariantHelperInterface"/>
            <argument>%shopware.es.dynamic_mapping_enabled%</argument>
            <argument>%shopware.es.debug%</argument>

            <tag name="shopware_elastic_search.mapping"/>
        </service>

        <service id="shopware_elastic_search.orm_backlog_save_subscriber"
                 class="Shopware\Bundle\ESIndexingBundle\Subscriber\ORMBacklogSaveSubscriber">
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\Subscriber\ORMBacklogSubscriber"/>
            <argument type="service" id="service_container"/>

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

        <service id="shopware_elastic_search.orm_backlog_subscriber"
                 class="Shopware\Bundle\ESIndexingBundle\Subscriber\ORMBacklogSubscriber">
            <argument type="service" id="service_container"/>

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

        <service id="shopware_elastic_search.domain_backlog_subscriber"
                 class="Shopware\Bundle\ESIndexingBundle\Subscriber\DomainBacklogSubscriber">
            <argument type="service" id="service_container"/>

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

        <service class="Shopware\Bundle\ESIndexingBundle\Product\ProductListingVariationLoader"
                 id="shopware_elastic_search.product_listing_variation_loader">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="Shopware\Bundle\ESIndexingBundle\IdentifierSelector"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface"/>
            <argument type="service" id="Shopware\Bundle\SearchBundleDBAL\ListingPriceHelper"/>
            <argument type="service" id="Shopware_Components_Config"/>
        </service>

        <service class="Shopware\Bundle\ESIndexingBundle\Product\ProductConfigurationLoader"
                 id="shopware_elastic_search.product_configuration_loader">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\Hydrator\ConfiguratorHydrator"/>
            <argument type="service" id="Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\FieldHelper"/>
            <argument type="service" id="Shopware_Components_Config"/>
        </service>

        <service class="Shopware\Bundle\ESIndexingBundle\Product\ProductManualPositionLoader" id="shopware_bundle_esindexing.product.product_manual_position_loader">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
        </service>

        <!-- Commands -->

        <service class="Shopware\Bundle\ESIndexingBundle\Commands\IndexPopulateCommand"
                 id="shopware_elastic_search.commands.index_populate_command">
            <argument type="service" id="models"/>
            <argument type="service" id="shopware_elastic_search.shop_indexer"/>
            <argument type="service" id="shopware_elastic_search.console.console_evaluation_helper"/>
            <argument type="service" id="shopware_elastic_search.identifier_selector"/>
            <argument type="service" id="shopware_storefront.shop_gateway_dbal"/>
            <tag name="console.command" command="sw:es:index:populate"/>
        </service>

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

        <service class="Shopware\Bundle\ESIndexingBundle\Commands\BacklogClearCommand"
                 id="shopware_elastic_search.commands.backlog_clear_command">
            <tag name="console.command" command="sw:es:backlog:clear"/>
        </service>

        <service class="Shopware\Bundle\ESIndexingBundle\Commands\BacklogSyncCommand"
                 id="shopware_elastic_search.commands.backlog_sync_command">
            <argument>%shopware.es.batchsize%</argument>
            <argument type="tagged" tag="shopware_elastic_search.mapping"/>

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

        <service class="Shopware\Bundle\ESIndexingBundle\Commands\SwitchAliasCommand"
                 id="shopware_elastic_search.commands.switch_alias_command">
            <tag name="console.command" command="sw:es:switch:alias"/>
        </service>

        <service class="Shopware\Bundle\ESIndexingBundle\Commands\AnalyzeCommand"
                 id="shopware_elastic_search.commands.analyze_command">
            <tag name="console.command" command="sw:es:analyze"/>
        </service>

        <service class="Shopware\Bundle\ESIndexingBundle\Console\ConsoleEvaluationHelper"
                 id="shopware_elastic_search.console.console_evaluation_helper">
        </service>
    </services>
</container>
