security:
    # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'

    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    providers:
        users_in_memory: { memory: null }
        user_in_database:
            entity:
                class: MyCoach\Entity\User
                property: email
        hook_key_user_provider:
            entity:
                class: MyCoach\Entity\User
                property: printHookKey

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

        hook:
            pattern: ^/hook
            stateless: true
            custom_authenticators:
                - MyCoach\Security\HookKeyAuthenticator
            provider: hook_key_user_provider

        main:
            lazy: true
            user_checker: MyCoach\Security\UserChecker

            form_login:
                login_path: auth_login
                check_path: auth_login
                default_target_path: auth_login
                
                provider: user_in_database

            logout:
                path: auth_logout
                target: auth_login

            # activate different ways to authenticate
            # https://symfony.com/doc/current/security.html#the-firewall

            # https://symfony.com/doc/current/security/impersonating_user.html
            # switch_user: true

    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
    access_control:
        - { path: ^/auth,             roles: [] }
        - { path: ^/site.webmanifest, roles: [] }
        - { path: ^/webhook,          roles: [] }
        - { path: ^/privacy,          roles: [] }
        - { path: ^/api/tools,        roles: [] }
        - { path: ^/asset,            roles: [] }

        - { path: ^/log/error,        roles: [] }
        - { path: ^/hook,             roles: ROLE_COACH }

        - { path: ^/admin,            roles: ROLE_ADMIN }
        
        - { path: ^/coach,            roles: ROLE_COACH }
        - { path: ^/cookie-consent,   roles: ROLE_COACH }
        - { path: ^/api/coaching,     roles: ROLE_COACH }

        - { path: ^/,                 roles: ROLE_USER }

        # - { path: ^/admin,   roles: ROLE_ADMIN }
        # - { path: ^/profile, roles: ROLE_USER }

when@test:
    security:
        password_hashers:
            # By default, password hashers are resource intensive and take time. This is
            # important to generate secure password hashes. In tests however, secure hashes
            # are not important, waste resources and increase test times. The following
            # reduces the work factor to the lowest possible values.
            Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
                algorithm: auto
                cost: 4 # Lowest possible value for bcrypt
                time_cost: 3 # Lowest possible value for argon
                memory_cost: 10 # Lowest possible value for argon
        # firewalls:
        #     hook:
        #         pattern: ^/hook
        #         stateless: true
        #         custom_authenticators:
        #             - MyCoach\Security\HookKeyAuthenticator
        #         provider: hook_key_user_provider

# when@qual:
#     security:
#         firewalls:
#             hook:
#                 pattern: ^/hook
#                 stateless: true
#                 custom_authenticators:
#                     - MyCoach\Security\HookKeyAuthenticator
#                 provider: hook_key_user_provider

# when@prod:
#     security:
#         firewalls:
#             hook:
#                 pattern: ^/hook
#                 stateless: true
#                 custom_authenticators:
#                     - MyCoach\Security\HookKeyAuthenticator
#                 provider: hook_key_user_provider
