doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        # Configure server_version so Doctrine can use platform-specific SQL
        # optimisations (e.g. RETURNING clause in PostgreSQL, window functions, etc.)
        # Set to match the actual database version in your environment.
        server_version: '%env(string:DB_SERVER_VERSION)%'
    orm:
        # Never auto-generate proxy classes at runtime.
        # Pre-warm them during deployment: bin/console cache:warmup
        auto_generate_proxy_classes: false
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        filters:
            company_filter:
                class: App\Doctrine\CompanyFilter
                enabled: false   # enabled dynamically by CompanyContextSubscriber
        mappings:
            App:
                is_bundle: false
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
        # ── Second-Level Cache (SLC) ───────────────────────────────────────────
        # Caches frequently read, rarely mutated entities in Redis across requests.
        # Enable by setting DOCTRINE_SLC_ENABLED=true and configuring the Redis pool.
        second_level_cache:
            enabled: '%env(bool:DOCTRINE_SLC_ENABLED)%'
            region_cache_driver:
                type: pool
                pool: cache.second_level_cache
            region_lifetime: 600
            regions:
                default:
                    lifetime: 600
                    cache_driver:
                        type: pool
                        pool: cache.second_level_cache

when@dev:
    doctrine:
        orm:
            # Auto-generate proxies in dev for convenience.
            auto_generate_proxy_classes: true

when@test:
    doctrine:
        dbal:
            # "TEST_TOKEN" is typically set by ParaTest
            dbname_suffix: '_test%env(default::TEST_TOKEN)%'
        orm:
            auto_generate_proxy_classes: true
