from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional

@dataclass
class MonitorEvent:
    query: str
    response: Optional[str] = None
    model: Optional[str] = None
    prompt: Optional[str] = None
    retrieved_docs: Optional[List[Dict[str, Any]]] = None
    tokens_used: Optional[int] = None
    prompt_tokens: Optional[int] = None
    completion_tokens: Optional[int] = None
    latency_ms: Optional[float] = None
    cost: Optional[float] = None
    hallucination_score: Optional[float] = None
    retrieval_score: Optional[float] = None
    relevance_score: Optional[float] = None
    experiment_id: Optional[str] = None
    variant_id: Optional[str] = None
    metadata: Dict[str, Any] = field(default_factory=dict)

    def to_dict(self) -> Dict[str, Any]:
        return {k: v for k, v in self.__dict__.items() if v is not None}

@dataclass
class MonitorResponse:
    success: bool
    count: int = 0
    ids: List[str] = field(default_factory=list)
    error: Optional[str] = None
