"""
BQAS Configuration
"""
import os
from dataclasses import dataclass, field
from typing import Optional


@dataclass
class BQASConfig:
    """Configuration for BQAS framework."""

    # Ollama settings
    ollama_base_url: str = field(
        default_factory=lambda: os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
    )
    judge_model: str = field(
        default_factory=lambda: os.getenv("BQAS_JUDGE_MODEL", "qwen2.5:32b")
    )
    judge_timeout: float = 120.0

    # Voice service settings
    voice_service_url: str = field(
        default_factory=lambda: os.getenv("VOICE_SERVICE_URL", "http://localhost:8091")
    )

    # Klausur service settings (for RAG tests)
    klausur_service_url: str = field(
        default_factory=lambda: os.getenv("KLAUSUR_SERVICE_URL", "http://localhost:8086")
    )

    # Database settings
    db_path: str = field(
        default_factory=lambda: os.getenv("BQAS_DB_PATH", "bqas_history.db")
    )

    # Thresholds
    regression_threshold: float = 0.1  # Score drop threshold
    min_golden_score: float = 3.5  # Minimum acceptable score
    min_synthetic_score: float = 3.0
    min_rag_score: float = 3.5  # Minimum acceptable RAG score

    # Weights for composite score (Intent tests)
    intent_accuracy_weight: float = 0.4
    faithfulness_weight: float = 0.2
    relevance_weight: float = 0.2
    coherence_weight: float = 0.1
    safety_weight: float = 0.1

    # Weights for RAG composite score
    rag_retrieval_precision_weight: float = 0.25
    rag_operator_alignment_weight: float = 0.20
    rag_faithfulness_weight: float = 0.20
    rag_citation_accuracy_weight: float = 0.15
    rag_privacy_compliance_weight: float = 0.10
    rag_coherence_weight: float = 0.10

    # GitHub integration
    github_repo: Optional[str] = field(
        default_factory=lambda: os.getenv("BQAS_GITHUB_REPO")
    )
    github_token: Optional[str] = field(
        default_factory=lambda: os.getenv("GITHUB_TOKEN")
    )

    # Test generation
    synthetic_count_per_intent: int = 10
    include_typos: bool = True
    include_dialect: bool = True

    # RAG test settings
    rag_test_suite_path: str = "tests/bqas/golden_tests/golden_rag_correction_v1.yaml"

    @classmethod
    def from_env(cls) -> "BQASConfig":
        """Create config from environment variables."""
        return cls()
