from typing import List, Optional, Union, Dict, Any
from pydantic import BaseModel, Field, field_validator


class EvaluationRequest(BaseModel):
    """
    Client-side evaluation request model used by the SDK clients.
    """

    messages: List[Dict[str, Any]] = Field(..., description="A list of chat messages")
    system_message: Optional[str] = Field(
        None, description="System message for the evaluation"
    )
    tools: Optional[List[Dict[str, Any]]] = Field(
        None, description="Tools available for the evaluation"
    )
    evaluation_criteria: Optional[Union[str, List[str]]] = Field(
        None, description="Evaluation criteria"
    )
    evaluator_name: Optional[str] = Field(
        None,
        description="Name of an existing evaluator (group_id) to use. Mutually exclusive with evaluation_criteria.",
    )
    model_core: Optional[str] = Field(None, description="The model core for evaluation")
    trace: Optional[Any] = Field(
        None, description="MultiAgentTrace for trace evaluation"
    )

    tags: Optional[Dict[str, str]] = Field(
        None, description="Optional key-value pairs to tag and categorize the request"
    )

    evaluate_latest: Optional[bool] = Field(
        None,
        description="Whether to evaluate only the latest response or all responses. "
        "If not provided, API defaults apply (True for chat, False for traces).",
    )


class EvaluationResponse(BaseModel):
    """
    Client-side evaluation response model used by the SDK clients.
    """

    score: Optional[float] = Field(None, description="Evaluation score between 0 and 1")
    explanation: str = Field(description="Explanation of the evaluation result")

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "EvaluationResponse":
        """Create EvaluationResponse from dictionary"""
        return cls(**data)
