framework:
    messenger:
        failure_transport: failed

        # Three buses: Command, Query, Event (CQRS + Event-driven)
        default_bus: command.bus

        buses:
            command.bus:
                default_middleware: true
                middleware:
                    - App\Shared\Infrastructure\Messenger\AddCorrelationIdStampMiddleware
                    - App\Shared\Infrastructure\Messenger\CorrelationIdMiddleware
                    - doctrine_transaction

            query.bus:
                default_middleware: true
                middleware:
                    - App\Shared\Infrastructure\Messenger\AddCorrelationIdStampMiddleware
                    - App\Shared\Infrastructure\Messenger\CorrelationIdMiddleware

            event.bus:
                default_middleware:
                    allow_no_handlers: true
                middleware:
                    - App\Shared\Infrastructure\Messenger\AddCorrelationIdStampMiddleware
                    - App\Shared\Infrastructure\Messenger\CorrelationIdMiddleware
                    - App\Administration\Infrastructure\Middleware\PaginatedCacheInvalidationMiddleware
                    - App\Shared\Infrastructure\Messenger\MessengerMetricsMiddleware

        transports:
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    exchange:
                        name: classeo_messages
                        type: topic
                    queues:
                        messages:
                            binding_keys: ['#']
                retry_strategy:
                    service: App\Shared\Infrastructure\Messenger\FibonacciRetryStrategy

            failed:
                dsn: 'doctrine://default?queue_name=failed'

        routing:
            # Email events → async (non-blocking API responses)
            App\Administration\Domain\Event\UtilisateurInvite: async
            App\Administration\Domain\Event\InvitationRenvoyee: async
            App\Administration\Domain\Event\PasswordResetTokenGenerated: async
            App\Administration\Domain\Event\CompteActive: async
            App\Administration\Domain\Event\MotDePasseChange: async
            # CompteBloqueTemporairement: sync (SendLockoutAlertHandler = immediate security alert)
            # ConnexionReussie, ConnexionEchouee: sync (audit-only, no email)
            # Parent invitation events → async (email sending)
            App\Administration\Domain\Event\InvitationParentEnvoyee: async
            App\Administration\Domain\Event\InvitationParentActivee: async
            # Notification enseignants journée pédagogique → async (envoi d'emails)
            App\Administration\Domain\Event\JourneePedagogiqueAjoutee: async
            # Import élèves/enseignants → async (batch processing, peut être long)
            App\Administration\Application\Command\ImportStudents\ImportStudentsCommand: async
            App\Administration\Application\Command\ImportTeachers\ImportTeachersCommand: async
