<?php

declare(strict_types=1);

namespace App\Framework\Analytics;

use App\Framework\Config\Environment;

/**
 * Analytics-Konfiguration
 */
final readonly class AnalyticsConfig
{
    public function __construct(
        public bool $enabled = false,
        public float $samplingRate = 1.0,
        public bool $securityAnalyticsEnabled = true,
        public string $dataPath = '/var/www/html/storage/analytics',
        public int $bufferSize = 1000,
        public int $retentionDays = 365,
        public bool $trackPageViews = true,
        public bool $trackApiCalls = true,
        public bool $trackUserActions = true,
        public bool $trackErrors = true,
        public bool $trackPerformance = true,
        public array $sensitiveKeys = [
            'password', 'token', 'api_key', 'session', 'credit_card',
            'ssn', 'personal_id', 'auth_token', 'bearer', 'cookie',
        ]
    ) {
    }

    public static function fromEnvironment(Environment $env): self
    {
        return new self(
            enabled: $env->getBool('ANALYTICS_ENABLED', true),
            samplingRate: $env->getFloat('ANALYTICS_SAMPLING_RATE', 1.0),
            securityAnalyticsEnabled: $env->getBool('SECURITY_ANALYTICS_ENABLED', true),
            dataPath: $env->getString('ANALYTICS_DATA_PATH', '/var/www/html/storage/analytics'),
            bufferSize: $env->getInt('ANALYTICS_BUFFER_SIZE', 1000),
            retentionDays: $env->getInt('ANALYTICS_RETENTION_DAYS', 365),
            trackPageViews: $env->getBool('ANALYTICS_TRACK_PAGE_VIEWS', true),
            trackApiCalls: $env->getBool('ANALYTICS_TRACK_API_CALLS', true),
            trackUserActions: $env->getBool('ANALYTICS_TRACK_USER_ACTIONS', true),
            trackErrors: $env->getBool('ANALYTICS_TRACK_ERRORS', true),
            trackPerformance: $env->getBool('ANALYTICS_TRACK_PERFORMANCE', true),
        );
    }
}
