"""Pydantic models for the Polleo AI conversational-analytics endpoint."""
from __future__ import annotations

from typing import Any, Literal, Optional

from pydantic import BaseModel, Field


class ChatTurn(BaseModel):
    """One prior message in the conversation. Only role + text are kept — the
    data/SQL of previous answers are intentionally NOT echoed back to Claude to
    keep token usage down."""
    role: Literal["user", "assistant"]
    content: str


class ChatRequest(BaseModel):
    message: str
    # Prior turns (oldest first). The service trims this to the last few pairs.
    conversation_history: list[ChatTurn] = Field(default_factory=list)


class ChartConfig(BaseModel):
    type: Literal["bar", "line", "area", "pie"]
    x_key: str
    y_keys: list[str]
    title: str


class ChatResponse(BaseModel):
    message: str                              # Claude's text answer
    data: Optional[list[dict[str, Any]]] = None   # query rows (<= 500), if any
    chart: Optional[ChartConfig] = None       # chart hint, if Claude asked for one
    sql_executed: Optional[str] = None        # the SQL actually run (transparency)


class HealthResponse(BaseModel):
    status: Literal["ok", "not_configured"]
