<?php

declare(strict_types=1);

namespace App\Framework\Monitoring;

use App\Framework\Core\ValueObjects\Duration;

/**
 * Configuration for advanced monitoring system
 */
final readonly class MonitoringConfig
{
    public function __construct(
        public Duration $metricsRetention = new Duration(86400.0), // 24 hours
        public Duration $aggregationInterval = new Duration(300.0), // 5 minutes
        public Duration $slowResponseThreshold = new Duration(1.0), // 1 second
        public float $warningErrorRateThreshold = 0.05, // 5%
        public float $criticalErrorRateThreshold = 0.15, // 15%
        public float $warningFallbackRateThreshold = 0.10, // 10%
        public float $criticalFallbackRateThreshold = 0.25, // 25%
        public bool $enableRealTimeAlerts = true,
        public bool $enableTrendAnalysis = true,
        public bool $enablePerformanceAnalytics = true,
        public int $maxMetricsHistory = 10000,
        public array $alertChannels = ['log', 'webhook'],
    ) {
    }

    /**
     * Create production configuration
     */
    public static function production(): self
    {
        return new self(
            metricsRetention: Duration::fromDays(7),
            aggregationInterval: Duration::fromMinutes(1),
            slowResponseThreshold: Duration::fromMilliseconds(500),
            warningErrorRateThreshold: 0.02, // 2%
            criticalErrorRateThreshold: 0.05, // 5%
            warningFallbackRateThreshold: 0.05, // 5%
            criticalFallbackRateThreshold: 0.15, // 15%
            enableRealTimeAlerts: true,
            enableTrendAnalysis: true,
            enablePerformanceAnalytics: true,
            maxMetricsHistory: 50000,
            alertChannels: ['log', 'webhook', 'email'],
        );
    }

    /**
     * Create development configuration
     */
    public static function development(): self
    {
        return new self(
            metricsRetention: Duration::fromHours(4),
            aggregationInterval: Duration::fromMinutes(5),
            slowResponseThreshold: Duration::fromSeconds(2),
            warningErrorRateThreshold: 0.10, // 10%
            criticalErrorRateThreshold: 0.25, // 25%
            warningFallbackRateThreshold: 0.20, // 20%
            criticalFallbackRateThreshold: 0.40, // 40%
            enableRealTimeAlerts: false,
            enableTrendAnalysis: true,
            enablePerformanceAnalytics: true,
            maxMetricsHistory: 1000,
            alertChannels: ['log'],
        );
    }

    /**
     * Create high-performance configuration
     */
    public static function highPerformance(): self
    {
        return new self(
            metricsRetention: Duration::fromHours(12),
            aggregationInterval: Duration::fromSeconds(30),
            slowResponseThreshold: Duration::fromMilliseconds(100),
            warningErrorRateThreshold: 0.001, // 0.1%
            criticalErrorRateThreshold: 0.01, // 1%
            warningFallbackRateThreshold: 0.02, // 2%
            criticalFallbackRateThreshold: 0.05, // 5%
            enableRealTimeAlerts: true,
            enableTrendAnalysis: true,
            enablePerformanceAnalytics: true,
            maxMetricsHistory: 100000,
            alertChannels: ['webhook', 'metrics'],
        );
    }
}
