"""Context and metrics classes for structured logging."""

from dataclasses import dataclass, asdict
from typing import Optional, Dict, Any
import uuid


@dataclass
class RequestContext:
    """Global context passed with each request for tracing."""
    
    request_id: Optional[str] = None
    conversation_id: Optional[str] = None
    user_id: Optional[str] = None
    session_id: Optional[str] = None
    endpoint: Optional[str] = None
    
    def __post_init__(self):
        if self.request_id is None:
            self.request_id = uuid.uuid4().hex[:12]
    
    def to_dict(self) -> Dict[str, Any]:
        """Convert to dict, including None values."""
        return dict(asdict(self))


