<?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">
    <parameters>
        <parameter key="sylius.form.type.user_request_password_reset.validation_groups" type="collection">
            <parameter>sylius</parameter>
        </parameter>
        <parameter key="sylius.form.type.user_reset_password.validation_groups" type="collection">
            <parameter>sylius</parameter>
        </parameter>
        <parameter key="sylius.form.type.user_change_password.validation_groups" type="collection">
            <parameter>sylius</parameter>
        </parameter>
    </parameters>

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

        <service id="Sylius\Bundle\UserBundle\Console\Command\DemoteUserCommand">
            <tag name="console.command" />
        </service>

        <service id="Sylius\Bundle\UserBundle\Command\DemoteUserCommand" alias="Sylius\Bundle\UserBundle\Console\Command\DemoteUserCommand" />

        <service id="Sylius\Bundle\UserBundle\Console\Command\PromoteUserCommand">
            <tag name="console.command" />
        </service>

        <service id="Sylius\Bundle\UserBundle\Command\PromoteUserCommand" alias="Sylius\Bundle\UserBundle\Console\Command\PromoteUserCommand" />

        <service id="sylius.authentication.success_handler" class="Sylius\Bundle\UserBundle\Authentication\AuthenticationSuccessHandler" parent="security.authentication.success_handler" public="false" />

        <service id="sylius.authentication.failure_handler" class="Sylius\Bundle\UserBundle\Authentication\AuthenticationFailureHandler" parent="security.authentication.failure_handler" public="false" />

        <!-- Controllers -->
        <service id="sylius.controller.user_security" class="Sylius\Bundle\UserBundle\Controller\SecurityController">
            <argument type="service" id="security.authentication_utils" />
            <argument type="service" id="form.factory" />
            <call method="setContainer">
                <argument type="service" id="service_container" />
            </call>
        </service>

        <!-- Utils -->
        <service id="sylius.canonicalizer" class="Sylius\Component\User\Canonicalizer\Canonicalizer" />
        <service id="Sylius\Component\User\Canonicalizer\CanonicalizerInterface" alias="sylius.canonicalizer" />

        <service id="sylius.security.password_encoder" class="Sylius\Bundle\UserBundle\Security\UserPasswordEncoder">
            <argument type="service" id="security.encoder_factory" />
        </service>

        <service id="Sylius\Component\User\Security\UserPasswordEncoderInterface" alias="sylius.security.password_hasher" />

        <service id="sylius.security.password_hasher" class="Sylius\Bundle\UserBundle\Security\UserPasswordHasher">
            <argument type="service" id="security.password_hasher_factory" />
        </service>

        <service id="sylius.security.password_updater" class="Sylius\Component\User\Security\PasswordUpdater">
            <argument type="service" id="sylius.security.password_hasher" />
        </service>

        <service id="Sylius\Component\User\Security\PasswordUpdaterInterface" alias="sylius.security.password_updater" />

        <service id="sylius.security.user_login" class="Sylius\Bundle\UserBundle\Security\UserLogin">
            <argument type="service" id="security.token_storage" />
            <argument type="service" id="security.user_checker" />
            <argument type="service" id="event_dispatcher" />
        </service>
        <service id="Sylius\Bundle\UserBundle\Security\UserLoginInterface" alias="sylius.security.user_login" />

        <!-- Listeners -->
        <service id="sylius.listener.password_updater" class="Sylius\Bundle\UserBundle\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="doctrine.event_listener" event="prePersist" lazy="true" />
            <tag name="doctrine.event_listener" event="preUpdate" lazy="true" />
        </service>

        <service id="sylius.listener.user_mailer_listener" class="Sylius\Bundle\UserBundle\EventListener\MailerListener">
            <argument type="service" id="sylius.email_sender" />
            <tag name="kernel.event_listener" event="sylius.user.password_reset.request.pin" method="sendResetPasswordPinEmail" />
            <tag name="kernel.event_listener" event="sylius.user.password_reset.request.token" method="sendResetPasswordTokenEmail" />
            <tag name="kernel.event_listener" event="sylius.user.email_verification.token" method="sendVerificationTokenEmail" />
        </service>

        <!-- Forms -->
        <service id="sylius.form.type.user_login" class="Sylius\Bundle\UserBundle\Form\Type\UserLoginType">
            <tag name="form.type" />
        </service>

        <service id="sylius.form.type.user_request_password_reset" class="Sylius\Bundle\UserBundle\Form\Type\UserRequestPasswordResetType">
            <argument type="string">Sylius\Bundle\UserBundle\Form\Model\PasswordResetRequest</argument>
            <argument>%sylius.form.type.user_request_password_reset.validation_groups%</argument>
            <tag name="form.type" />
        </service>

        <service id="sylius.form.type.user_reset_password" class="Sylius\Bundle\UserBundle\Form\Type\UserResetPasswordType">
            <argument type="string">Sylius\Bundle\UserBundle\Form\Model\PasswordReset</argument>
            <argument>%sylius.form.type.user_reset_password.validation_groups%</argument>
            <tag name="form.type" />
        </service>

        <service id="sylius.form.type.user_change_password" class="Sylius\Bundle\UserBundle\Form\Type\UserChangePasswordType">
            <argument type="string">Sylius\Bundle\UserBundle\Form\Model\ChangePassword</argument>
            <argument>%sylius.form.type.user_change_password.validation_groups%</argument>
            <tag name="form.type" />
        </service>
    </services>
</container>
