# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
    APP_SECRET: '%env(resolve:APP_SECRET)%'
    JWT_PUBLIC_KEY: '%env(resolve:JWT_PUBLIC_KEY)%'
    senderName: '%env(resolve:sender_name)%'
    senderEmail: '%env(resolve:sender_email)%'
    public_directory: '%env(resolve:public_directory)%'
    uploads_directory: '%public_directory%/uploads'

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        bind:         
            $publicPath: '%public_directory%'
    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            # - '../src/Entity/'
            - '../src/Kernel.php'

    App\Service\FileUploader:
        arguments:
            $uploadPath: '%uploads_directory%'

    # Service d'envoi de mail d'uathentification (Frederic Schroder)
    App\Service\TwoFactorMailer:
        class: App\Service\TwoFactorMailer
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@mailer'
            - '%env(resolve:sender_email)%'
            - '%env(resolve:sender_name)%'

    App\EventListener\CampagneListener:
        tags:
            -
                name: 'doctrine.orm.entity_listener'
                event: 'prePersist'
                entity: 'App\Entity\Campagne'
            -
                name: 'doctrine.orm.entity_listener'
                event: 'postLoad'
                entity: 'App\Entity\Campagne'
            -
                name: 'doctrine.orm.entity_listener'
                event: 'preUpdate'
                entity: 'App\Entity\Campagne'
 
        arguments:
            $appsecret: '%env(resolve:APP_SECRET)%'

    App\EventListener\CaptchaListener:
        tags:
            -
                name: 'doctrine.event_listener'
                event: 'preUpdate'
                priority: 500
                connection: 'default'
            -
                name: 'doctrine.event_listener'
                event: 'prePersist'
                priority: 500
                connection: 'default'

    App\EventListener\CommentListener:
        tags:
            -
                name: 'doctrine.orm.entity_listener'
                event: 'prePersist'
                entity: 'App\Entity\Comment'
            -
                name: 'doctrine.orm.entity_listener'
                event: 'postUpdate'
                entity: 'App\Entity\Comment'
            -
                name: 'doctrine.orm.entity_listener'
                event: 'postLoad'
                entity: 'App\Entity\Comment'

    App\EventListener\IdeaListener:
        tags:
            -
                name: 'doctrine.orm.entity_listener'
                event: 'prePersist'
                entity: 'App\Entity\Idea'
            -
                name: 'doctrine.orm.entity_listener'
                event: 'preUpdate'
                entity: 'App\Entity\Idea'
            -
                name: 'doctrine.orm.entity_listener'
                event: 'postLoad'
                entity: 'App\Entity\Idea'

    App\EventListener\ReponseListener:
        tags:
            -
                name: 'doctrine.orm.entity_listener'
                event: 'prePersist'
                entity: 'App\Entity\Reponse'

    App\EventListener\ThemeListener:
        tags:
            -
                name: 'doctrine.orm.entity_listener'
                event: 'preRemove'
                entity: 'App\Entity\Theme'

    App\EventListener\ReponsePossibleListener:
        tags:
            -
                name: 'doctrine.orm.entity_listener'
                event: 'preRemove'
                entity: 'App\Entity\ReponsePossible'

            -
                name: 'doctrine.orm.entity_listener'
                event: 'preUpdate'
                entity: 'App\Entity\ReponsePossible'

    App\EventListener\QuestionListener:
        tags:
            -
                name: 'doctrine.orm.entity_listener'
                event: 'preRemove'
                entity: 'App\Entity\Question'

            -
                name: 'doctrine.orm.entity_listener'
                event: 'preUpdate'
                entity: 'App\Entity\Question'

    App\EventListener\LogsListener:
        tags:
            -
                name: 'kernel.event_listener'
                event: 'kernel.terminate'
                method: 'onKernelTerminate'
            -   
                name: 'monolog.logger'
                channel: 'request_log'

    App\EventListener\RepondantListener:
        tags:
            -
                name: 'doctrine.orm.entity_listener'
                event: 'prePersist'
                entity: 'App\Entity\Repondant'