"""Assistant mode request/response schemas."""

from __future__ import annotations

from pydantic import BaseModel, Field, field_validator


class AssistantQueryRequest(BaseModel):
    """Input payload for assistant query endpoint."""

    message: str = Field(..., min_length=1)

    @field_validator("message")
    @classmethod
    def _strip_message(cls, value: str) -> str:
        text = value.strip()
        if not text:
            raise ValueError("message cannot be empty")
        return text


class AssistantQueryResponse(BaseModel):
    """Output payload for assistant query endpoint."""

    intent: str
    response: str


class AssistantChatRequest(BaseModel):
    """Input payload for assistant chat endpoint."""

    message: str = Field(..., min_length=1)
    session_id: str | None = Field(default=None, min_length=1, max_length=128)

    @field_validator("message")
    @classmethod
    def _strip_message(cls, value: str) -> str:
        text = value.strip()
        if not text:
            raise ValueError("message cannot be empty")
        return text

    @field_validator("session_id")
    @classmethod
    def _strip_session_id(cls, value: str | None) -> str | None:
        if value is None:
            return None
        text = value.strip()
        return text or None


class AssistantChatResponse(BaseModel):
    """Output payload for assistant chat endpoint."""

    session_id: str
    response: str


class AssistantMarkdownRenderRequest(BaseModel):
    """Payload for server-side markdown rendering."""

    text: str = Field(default="")


class AssistantMarkdownRenderResponse(BaseModel):
    """Server-side rendered markdown payload."""

    html: str


class AssistantUiPromptRequest(BaseModel):
    """Input payload for App Mode text prompt submission."""

    message: str = Field(..., min_length=1)

    @field_validator("message")
    @classmethod
    def _strip_message_for_ui(cls, value: str) -> str:
        text = value.strip()
        if not text:
            raise ValueError("message cannot be empty")
        return text
