security:
    password_hashers:
        App\Entity\User:
            algorithm: auto

    providers:
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email

    enable_authenticator_manager: true

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        # 🔒 Authentification via formulaire HTML
        main:
            pattern: ^/
            lazy: true
            provider: app_user_provider
            form_login:
                login_path: app_login        # GET login form
                check_path: app_login        # POST login form
                enable_csrf: true
            logout:
                path: app_logout
                target: app_login

        # 🔒 Authentification API (React Native)
        api_login:
            pattern: ^/api/login
            stateless: true
            provider: app_user_provider
            json_login:
                check_path: /api/login
                username_path: email
                password_path: password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure

        # 🔒 Accès aux routes protégées de l’API (JWT)
        api:
            pattern: ^/api
            stateless: true
            provider: app_user_provider
            jwt: ~

    access_control:
        # Autoriser accès public au login web
        - { path: ^/login, roles: PUBLIC_ACCESS }
        # Autoriser accès public au login API
        - { path: ^/api/login, roles: PUBLIC_ACCESS }
        # Protéger toutes les routes API (JWT requis)
        - { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
        # Protéger tout le reste (web) avec ROLE_ADMIN
        - { path: ^/, roles: ROLE_ADMIN }
