"""Shared pattern configuration classes for telemetry generation."""

from dataclasses import dataclass
from enum import Enum
from typing import Literal, Optional


class MetricScale(Enum):
    """Predefined scale ranges for metric values."""

    TENS = (10, 100)
    HUNDREDS = (100, 1000)
    THOUSANDS = (1000, 10000)
    TEN_THOUSANDS = (10000, 100000)
    HUNDRED_THOUSANDS = (100000, 1000000)
    MILLIONS = (1000000, 10000000)
    TEN_MILLIONS = (10000000, 100000000)
    HUNDRED_MILLIONS = (100000000, 1000000000)


@dataclass
class SeasonalityConfig:
    """Configuration for seasonal patterns in data."""

    pattern: Literal["weekly", "monthly", "yearly"]
    amplitude: float
    phase: float = 0


@dataclass
class TrendConfig:
    """Configuration for trend patterns in data."""

    type: Literal["linear", "exponential", "logistic"]
    growth_rate: float
    cap: Optional[float] = None  # For logistic growth


@dataclass
class AnomalyConfig:
    """Configuration for anomaly injection in data."""

    frequency: float  # Anomalies per month
    magnitude: float  # Multiplier for base value
    duration: int  # Days
    seed: int = 42  # For reproducible anomaly placement


@dataclass
class PatternConfig:
    """Container for all pattern configurations."""

    variance_factor: float = 0.2
    seasonality: Optional[SeasonalityConfig] = None
    trend: Optional[TrendConfig] = None
    anomaly: Optional[AnomalyConfig] = None

    def __post_init__(self):
        """Convert dict values to appropriate types if needed."""
        # Convert seasonality dict to SeasonalityConfig
        if self.seasonality and isinstance(self.seasonality, dict):
            self.seasonality = SeasonalityConfig(**self.seasonality)

        # Convert trend dict to TrendConfig
        if self.trend and isinstance(self.trend, dict):
            self.trend = TrendConfig(**self.trend)

        # Convert anomaly dict to AnomalyConfig
        if self.anomaly and isinstance(self.anomaly, dict):
            self.anomaly = AnomalyConfig(**self.anomaly)
