# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
    timezone: '%env(APP_TIMEZONE)%'
    app.timezone: '%env(APP_TIMEZONE)%'
    app.log_directory: '%kernel.project_dir%/var/logs'
    app.alert_email_recipients: '%env(ALERT_EMAIL_RECIPIENTS)%'
    app.support_email: '%env(SUPPORT_EMAIL)%'
    app.system_name: '%env(SYSTEM_NAME)%'
    app.base_url: '%env(BASE_URL)%'
    app.version: '%env(APP_VERSION)%'
    base_url: '%env(BASE_URL)%'
    system_name: '%env(SYSTEM_NAME)%'
    # Nouveaux paramètres système
    app.backup_directory: '%app.log_directory%/base_de_donnee'
    app.backup_retention_days: 30
    app.media_directory: '%kernel.project_dir%/var/media'

    # Paramètres de blocage IP (depuis .env)
    app.ip_blocking.max_requests_per_minute: '%env(int:IP_MAX_REQUESTS_PER_MINUTE)%'
    app.ip_blocking.max_failed_rate: '%env(float:IP_MAX_FAILED_RATE)%'
    app.ip_blocking.threat_score_threshold: '%env(int:IP_THREAT_SCORE_THRESHOLD)%'
    app.ip_blocking.auto_block_duration: '%env(int:IP_AUTO_BLOCK_DURATION)%'

    # Paramètres de calcul du score de menace - Taux d'échec
    app.ip_monitoring.failed_rate_high: '%env(int:IP_FAILED_RATE_HIGH)%'
    app.ip_monitoring.failed_rate_medium: '%env(int:IP_FAILED_RATE_MEDIUM)%'
    app.ip_monitoring.failed_rate_low: '%env(int:IP_FAILED_RATE_LOW)%'

    # Paramètres de calcul du score de menace - Taux de requêtes
    app.ip_monitoring.request_rate_high: '%env(int:IP_REQUEST_RATE_HIGH)%'
    app.ip_monitoring.request_rate_medium: '%env(int:IP_REQUEST_RATE_MEDIUM)%'
    app.ip_monitoring.request_rate_low: '%env(int:IP_REQUEST_RATE_LOW)%'

    # Paramètres de calcul du score de menace - Patterns suspects
    app.ip_monitoring.proxy_score: '%env(int:IP_PROXY_SCORE)%'
    app.ip_monitoring.vpn_score: '%env(int:IP_VPN_SCORE)%'
    app.ip_monitoring.tor_score: '%env(int:IP_TOR_SCORE)%'

    # Paramètres des niveaux de risque
    app.ip_monitoring.risk_critical_threshold: '%env(int:IP_RISK_CRITICAL_THRESHOLD)%'
    app.ip_monitoring.risk_high_threshold: '%env(int:IP_RISK_HIGH_THRESHOLD)%'
    app.ip_monitoring.risk_medium_threshold: '%env(int:IP_RISK_MEDIUM_THRESHOLD)%'

    # Paramètres de rate limiting utilisateur
    app.rate_limit.max_failed_attempts: '%env(int:RATE_LIMIT_MAX_ATTEMPTS)%'
    app.rate_limit.lock_duration_minutes: '%env(int:RATE_LIMIT_LOCK_DURATION)%'
    app.rate_limit.attempt_window_minutes: '%env(int:RATE_LIMIT_ATTEMPT_WINDOW)%'

    # Paramètres d'activation des blocages automatiques
    app.enable_auto_ip_blocking: '%env(bool:ENABLE_AUTO_IP_BLOCKING)%'
    app.enable_auto_account_lock: '%env(bool:ENABLE_AUTO_ACCOUNT_LOCK)%'

    # Paramètres de logging HTTP
    app.http_logging.enabled: true
    app.http_logging.log_all_routes: true
    app.http_logging.max_body_size: 5000
    app.http_logging.max_api_body_size: 10000  # Max size for API request body capture (10KB)
    app.http_logging.excluded_routes:
        - '^/_profiler'
        - '^/_wdt'
        - '^/_error'

    # Paramètres de sécurité IP
    app.ip_blocking.notification_only: false
    app.ip_blocking.threat_threshold: 50
    app.ip_blocking.whitelist: ['127.0.0.1', '::1']
    app.ip_blocking.suspicious_countries: []
    app.ip_blocking.suspicious_paths:
        - '/wp-login'
        - '/wp-admin'
        - '/.env'
        - '/phpinfo'
        - '/.git'
        - '/xmlrpc.php'
        - '/actuator'
        - '/solr'
        - '/console'
        - '/vendor/phpunit'
        - '/telescope'
        - '/debug'
        - '/phpmyadmin'
        - '/pma'
        - '/administrator'
        - '/cgi-bin'
        - '/wp-content'
        - '/wp-includes'

    # Notifications de sécurité
    app.security.notification_email: '%env(SUPPORT_EMAIL)%'
    app.security.enable_token_security_validation: '%env(bool:ENABLE_TOKEN_SECURITY_VALIDATION)%'
    app.security.enable_token_location_check: '%env(bool:ENABLE_TOKEN_LOCATION_CHECK)%'
    app.security.enable_user_agent_check: '%env(bool:ENABLE_USER_AGENT_CHECK)%'

    # Paramètres de gestion des appareils
    app.device.approval_code_lifetime: 900  # 15 minutes en secondes
    app.device.cleanup_inactive_days: 90    # Supprimer les appareils inactifs après 90 jours
    app.device.notify_admin_on_new: false    # Notifier l'admin pour chaque nouvel appareil
    app.device.notify_admin_on_suspicious: true  # Notifier l'admin pour activité suspecte

    # Paramètres JWT et Refresh Token
    refresh_token_ttl: 604800  # 7 jours en secondes (7 * 24 * 60 * 60)
    refresh_token_rotation_window: 300  # 5 minutes en secondes

    # Paramètres Messenger
    app.messenger.mode: '%env(MESSENGER_MODE)%'

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        bind:
            # Bind ParameterBagInterface to make it autowirable
            Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface: '@parameter_bag'

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones
    App\Service\Logging\FileLogger:
        arguments:
            $logDirectory: '%app.log_directory%'
        calls:
            - [setEmailService, ['@App\Service\Email\EmailService']]
            - [setTwig, ['@twig']]
            - [setSupportEmail, ['%env(SUPPORT_EMAIL)%']]
            - [enableEmailNotification, [true]]  # Activé pour les notifications d'erreur
            - [setMaxEmailsPerWindow, [20]]  # Augmenter pour dev (5 → 20 emails par minute)
            - [setRateLimitWindow, [60]]  # Fenêtre de 60 secondes

    # Configuration du service de backup de base de données
    App\Service\System\DatabaseBackupService:
        arguments:
            $logDirectory: '%app.log_directory%'
            $retentionDays: '%app.backup_retention_days%'

    # Configuration du service de gestion des médias
    App\Service\Media\MediaService:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du MediaController (pour servir les médias privés)
    App\Controller\MediaController:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du ApiMediaController (API pour servir les médias)
    App\Controller\Api\MediaController:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du AdminMediaController (Admin pour gestion des médias)
    App\Controller\Admin\AdminMediaController:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du ManagerMediaController (Manager pour visualisation des médias)
    App\Controller\Manager\ManagerMediaController:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du MediaViewController (Contrôleur unifié pour visualisation des médias)
    App\Controller\MediaViewController:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du ProductController POS (Manager)
    App\Controller\Manager\Pos\ProductController:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du SystemController
    App\Controller\Admin\SystemController:
        arguments:
            $cacheDir: '%kernel.cache_dir%'
            $logDir: '%app.log_directory%'
            $projectDir: '%kernel.project_dir%'

    # Configuration du CacheManagementService
    App\Service\System\CacheManagementService:
        arguments:
            $cacheDirectory: '%kernel.cache_dir%'
            $logDirectory: '%app.log_directory%'

    # Configuration du JwtTokenService
    App\Service\Auth\JwtTokenService:
        arguments:
            $securityAlertAdminEmail: '%app.security.notification_email%'

    # Configuration du MessengerConfigService
    App\Service\Messenger\MessengerConfigService:
        arguments:
            $messengerMode: '%app.messenger.mode%'

    # Configuration du DynamicTransportMiddleware
    App\Messenger\Middleware\DynamicTransportMiddleware:
        arguments:
            $messengerMode: '%app.messenger.mode%'

    # Configuration du SyncErrorHandlerMiddleware
    App\Messenger\Middleware\SyncErrorHandlerMiddleware:
        arguments:
            $messengerMode: '%app.messenger.mode%'
        tags:
            - { name: 'monolog.logger', channel: 'messenger' }

    # Configuration du UserMediaController
    App\Controller\User\UserMediaController:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du ZipArchiveService
    App\Service\Media\ZipArchiveService:
        arguments:
            $mediaDirectory: '%app.media_directory%'

    # Configuration du TokenSecurityListener
    App\EventListener\TokenSecurityListener:
        arguments:
            $enableTokenSecurityValidation: '%app.security.enable_token_security_validation%'

    

    # Configuration de l'écouteur de version d'application
    App\EventListener\AppVersionListener:
        arguments:
            $appVersion: '%app.version%'