security:
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'

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

    firewalls:
        # Endpoint de connexion JWT : POST /api/login_check {email, password} -> {token}
        login:
            pattern: ^/api/login_check
            stateless: true
            json_login:
                check_path: /api/login_check
                username_path: email
                password_path: password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure

        # Toute l'API est stateless et protégée par JWT (les opérations publiques
        # sont autorisées via les attributs `security` sur chaque ApiResource)
        api:
            pattern: ^/api
            stateless: true
            jwt: ~

        # Back-office admin (EasyAdmin) : authentification classique par formulaire + session
        main:
            lazy: true
            provider: app_user_provider
            form_login:
                login_path: app_admin_login
                check_path: app_admin_login
                default_target_path: admin
                username_parameter: email
                password_parameter: password
            logout:
                path: app_admin_logout
                target: app_home

    access_control:
        - { path: ^/api/login_check, roles: PUBLIC_ACCESS }
        - { path: ^/api/docs, roles: PUBLIC_ACCESS }
        - { path: ^/api, roles: PUBLIC_ACCESS } # affinage fin délégué aux attributs `security` d'API Platform
        - { path: ^/admin/login, roles: PUBLIC_ACCESS }
        - { path: ^/admin, roles: ROLE_ADMIN }

when@test:
    security:
        password_hashers:
            Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
                algorithm: auto
                cost: 4
                time_cost: 3
                memory_cost: 10
