<?xml version="1.0" encoding="UTF-8"?>

<!--

 This file is part of the Sylius package.

 (c) Sylius Sp. z o.o.

 For the full copyright and license information, please view the LICENSE
 file that was distributed with this source code.

-->

<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">
    <imports>
        <import resource="listeners/workflow/*.xml" />
    </imports>

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

        <service id="sylius.listener.channel" class="Sylius\Bundle\CoreBundle\EventListener\ChannelDeletionListener">
            <argument type="service" id="sylius.checker.channel_deletion" />
            <tag name="kernel.event_listener" event="sylius.channel.pre_delete" method="onChannelPreDelete" />
        </service>

        <service id="sylius.listener.images_upload" class="Sylius\Bundle\CoreBundle\EventListener\ImagesUploadListener">
            <argument type="service" id="sylius.image_uploader" />
            <tag name="kernel.event_listener" event="sylius.product.pre_create" method="uploadImages" />
            <tag name="kernel.event_listener" event="sylius.product.pre_update" method="uploadImages" />
            <tag name="kernel.event_listener" event="sylius.taxon.pre_create" method="uploadImages" />
            <tag name="kernel.event_listener" event="sylius.taxon.pre_update" method="uploadImages" />
        </service>

        <service id="sylius.listener.images_remove" class="Sylius\Bundle\CoreBundle\EventListener\ImagesRemoveListener">
            <argument type="service" id="sylius.image_uploader" />
            <argument type="service" id="liip_imagine.cache.manager" />
            <argument type="service" id="liip_imagine.filter.manager" />
            <tag name="doctrine.event_listener" event="onFlush" lazy="true" />
            <tag name="doctrine.event_listener" event="postFlush" lazy="true" />
        </service>

        <service id="sylius.listener.avatar_upload" class="Sylius\Bundle\CoreBundle\EventListener\ImageUploadListener">
            <argument type="service" id="sylius.image_uploader" />
            <tag name="kernel.event_listener" event="sylius.admin_user.pre_create" method="uploadImage" />
            <tag name="kernel.event_listener" event="sylius.admin_user.pre_update" method="uploadImage" />
        </service>

        <service id="sylius.listener.order_recalculation" class="Sylius\Bundle\CoreBundle\EventListener\OrderRecalculationListener">
            <argument type="service" id="sylius.order_processing.order_processor" />
            <tag name="kernel.event_listener" event="sylius.cart_change" method="recalculateOrder" />
        </service>

        <service id="sylius.listener.default_username" class="Sylius\Bundle\CoreBundle\EventListener\DefaultUsernameORMListener">
            <tag name="doctrine.event_listener" event="onFlush" lazy="true" />
        </service>

        <service id="sylius.listener.canonicalizer" class="Sylius\Bundle\CoreBundle\EventListener\CanonicalizerListener">
            <argument type="service" id="sylius.canonicalizer" />
            <tag name="doctrine.event_listener" event="prePersist" lazy="true" />
            <tag name="doctrine.event_listener" event="preUpdate" lazy="true" />
        </service>

        <service id="sylius.listener.password_updater" class="Sylius\Bundle\CoreBundle\EventListener\PasswordUpdaterListener">
            <argument type="service" id="sylius.security.password_updater" />
            <tag name="kernel.event_listener" event="sylius.user.pre_password_reset" method="genericEventUpdater" />
            <tag name="kernel.event_listener" event="sylius.user.pre_password_change" method="genericEventUpdater" />
            <tag name="kernel.event_listener" event="sylius.admin_user.pre_update" method="genericEventUpdater" />
            <tag name="kernel.event_listener" event="sylius.customer.pre_update" method="customerUpdateEvent" />
            <tag name="doctrine.event_listener" event="prePersist" lazy="true" />
            <tag name="doctrine.event_listener" event="preUpdate" lazy="true" />
        </service>

        <service id="sylius.listener.review_create" class="Sylius\Bundle\CoreBundle\EventListener\ReviewCreateListener">
            <argument type="service" id="sylius.context.customer" />
            <tag name="kernel.event_listener" event="sylius.product_review.pre_create" method="ensureReviewHasAuthor" />
        </service>

        <service id="sylius.listener.locking" class="Sylius\Bundle\CoreBundle\EventListener\LockingListener">
            <argument type="service" id="doctrine.orm.entity_manager" />
            <tag name="kernel.event_listener" event="sylius.product_variant.initialize_update" method="lock" />
        </service>

        <service id="sylius.listener.simple_product_locking" class="Sylius\Bundle\CoreBundle\EventListener\SimpleProductLockingListener">
            <argument type="service" id="doctrine.orm.entity_manager" />
            <tag name="kernel.event_listener" event="sylius.product.initialize_update" method="lock" />
        </service>

        <service id="sylius.listener.customer_default_address" class="Sylius\Bundle\CoreBundle\EventListener\CustomerDefaultAddressListener">
            <tag name="kernel.event_listener" event="sylius.address.pre_create" method="preCreate" />
        </service>

        <service id="Sylius\Bundle\CoreBundle\EventListener\LocaleAwareListener" decorates="locale_aware_listener">
            <argument type="service" id="Sylius\Bundle\CoreBundle\EventListener\LocaleAwareListener.inner" />
        </service>

        <service id="Sylius\Bundle\CoreBundle\EventListener\XFrameOptionsSubscriber">
            <tag name="kernel.event_subscriber" />
        </service>

        <service id="sylius.listener.taxon_deletion" class="Sylius\Bundle\CoreBundle\EventListener\TaxonDeletionListener">
            <argument type="service" id="request_stack" />
            <argument type="service" id="sylius.repository.channel" />
            <argument type="service" id="Sylius\Component\Core\Promotion\Checker\TaxonInPromotionRuleCheckerInterface" />
            <argument type="service" id="sylius.promotion_rule_updater.total_of_items_from_taxon" />
            <argument type="service" id="sylius.promotion_rule_updater.has_taxon" />
            <tag name="kernel.event_listener" event="sylius.taxon.pre_delete" method="protectFromRemovingMenuTaxon" />
            <tag name="kernel.event_listener" event="sylius.taxon.post_delete" method="removeTaxonFromPromotionRules" />
            <tag name="kernel.event_listener" event="sylius.taxon.pre_delete" method="handleRemovingRootTaxonAtPositionZero" />
            <tag name="kernel.event_listener" event="sylius.taxon.pre_delete" method="protectFromRemovingTaxonInUseByPromotionRule" />
        </service>

        <service id="Sylius\Bundle\CoreBundle\EventListener\PaymentPreCompleteListener">
            <argument type="service" id="sylius.inventory.order_item_availability_checker" />
            <tag name="kernel.event_listener" event="sylius.payment.pre_complete" method="checkStockAvailability" />
        </service>

        <service id="Sylius\Bundle\CoreBundle\EventListener\ProductDeletionListener">
            <argument type="service" id="Sylius\Component\Core\Promotion\Checker\ProductInPromotionRuleCheckerInterface" />
            <tag name="kernel.event_listener" event="sylius.product.pre_delete" method="protectFromRemovingProductInUseByPromotionRule" />
        </service>

        <service id="Sylius\Bundle\CoreBundle\EventListener\PostgreSQLDefaultSchemaListener">
            <tag name="doctrine.event_listener" event="postGenerateSchema" method="postGenerateSchema" lazy="true" />
        </service>
    </services>
</container>
