"""Configuration for research service."""

from dataclasses import dataclass
from typing import Optional


@dataclass
class ResearchConfig:
    """Configuration for research service."""
    
    # API Configuration
    api_key: str
    base_url: str = "https://openrouter.ai/api/v1"
    timeout: int = 60
    max_retries: int = 3
    
    # Model Configuration
    default_model: str = "perplexity/sonar-reasoning-pro"
    max_tokens: int = 4000
    temperature: float = 0.1
    
    # Rate Limiting
    requests_per_minute: int = 60
    tokens_per_minute: int = 100000
    
    # Caching
    enable_cache: bool = True
    cache_ttl_seconds: int = 3600  # 1 hour
    
    # Response Settings
    include_sources: bool = True
    max_sources: int = 10
    
    @classmethod
    def from_env(cls, api_key: str) -> "ResearchConfig":
        """Create config from environment variables."""
        return cls(api_key=api_key)
    
    def validate(self) -> None:
        """Validate configuration."""
        if not self.api_key:
            raise ValueError("API key is required")
        
        if self.max_tokens <= 0:
            raise ValueError("max_tokens must be positive")
        
        if not 0 <= self.temperature <= 2:
            raise ValueError("temperature must be between 0 and 2")
        
        if self.timeout <= 0:
            raise ValueError("timeout must be positive")
