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

    # Role hierarchy
    role_hierarchy:
        ROLE_WRITER: ROLE_USER
        ROLE_ADMIN: [ROLE_USER, ROLE_WRITER]
    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
        api_user_provider:
            entity:
                class: App\Entity\User
                property: apiToken
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        login:
            pattern: ^/api/login_check
            stateless: true
            security: false
        user_create:
            pattern: ^/api/users/create
            stateless: true
            security: false
        api:
            pattern: ^/api/
            provider: api_user_provider
            custom_authenticator: App\Security\APIAuthenticator
            entry_point: App\Security\APIAuthenticator
            stateless: true
            lazy: true
        main:
            lazy: true
            provider: app_user_provider

            # 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
    # Attention : IS_AUTHENTICATED_ANONYMOUSLY est déprécié, utilisez PUBLIC_ACCESS en Symfony 6+
    access_control:
        - { path: ^/api/login_check, roles: PUBLIC_ACCESS }
        # User management
        - { path: ^/api/users/create, roles: PUBLIC_ACCESS } # Allow user registration
        - { path: ^/api/users/edit, roles: ROLE_USER } # Users can edit their own profiles
        - { path: ^/api/users/delete, roles: ROLE_ADMIN } # Only admins can delete users
        # Create operations require ROLE_WRITER
        - { path: ^/api/blogs/create, roles: ROLE_WRITER }
        - { path: ^/api/categories/create, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/characters/create, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/charactertraits/create, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/colors/create, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/genders/create, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/illustrations/create, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/titles/create, roles: ROLE_WRITER }
        - { path: ^/api/planning/create, roles: ROLE_WRITER }
        - { path: ^/api/projets/create, roles: ROLE_WRITER }
        # Edit operations require ROLE_WRITER
        - { path: ^/api/blogs/edit, roles: ROLE_WRITER }
        - { path: ^/api/categories/edit, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/characters/edit, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/charactertraits/edit, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/colors/edit, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/genders/edit, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/illustrations/edit, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/titles/edit, roles: ROLE_WRITER }
        - { path: ^/api/planning/edit, roles: ROLE_WRITER }
        - { path: ^/api/projets/edit, roles: ROLE_WRITER }
        # Delete operations require ROLE_WRITER
        - { path: ^/api/blogs/delete, roles: ROLE_WRITER }
        - { path: ^/api/categories/delete, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/characters/delete, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/charactertraits/delete, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/colors/delete, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/genders/delete, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/illustrations/delete, roles: ROLE_WRITER }
        - { path: ^/api/moodboards/titles/delete, roles: ROLE_WRITER }
        - { path: ^/api/planning/delete, roles: ROLE_WRITER }
        - { path: ^/api/projets/delete, roles: ROLE_WRITER }
        # All other API routes require ROLE_USER
        - { path: ^/api, 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
