"""
Configuration du service ASR
"""

from dataclasses import dataclass
from typing import Dict, Any


@dataclass
class ASRConfig:
    """Configuration du service ASR."""

    # Langue par défaut
    lang: str = "fr"

    # Paramètres audio
    sample_rate: int = 16000
    channels: int = 1
    chunk_size: int = 1024

    # Paramètres VAD et EOS
    eos_ms: int = 800
    vad_threshold: float = 0.5

    # Paramètres MQTT
    mqtt_host: str = "127.0.0.1"
    mqtt_port: int = 1883

    # Chemin des modèles
    model_base_path: str = "/opt/Skull/models"

    def to_dict(self) -> Dict[str, Any]:
        """Convertit la configuration en dictionnaire."""
        return {
            "lang": self.lang,
            "sample_rate": self.sample_rate,
            "channels": self.channels,
            "chunk_size": self.chunk_size,
            "eos_ms": self.eos_ms,
            "vad_threshold": self.vad_threshold,
            "mqtt_host": self.mqtt_host,
            "mqtt_port": self.mqtt_port,
            "model_base_path": self.model_base_path,
        }

    def update_from_dict(self, config_dict: Dict[str, Any]) -> None:
        """Met à jour la configuration depuis un dictionnaire."""
        for key, value in config_dict.items():
            if hasattr(self, key):
                setattr(self, key, value)

    def validate(self) -> bool:
        """Valide la configuration."""
        if self.lang not in ["fr", "en"]:
            return False

        if self.sample_rate not in [8000, 16000, 44100, 48000]:
            return False

        if self.eos_ms < 100 or self.eos_ms > 5000:
            return False

        if self.vad_threshold < 0.0 or self.vad_threshold > 1.0:
            return False

        return True
