# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import List, Union, Optional
from typing_extensions import Literal, Annotated, TypeAlias

from .._utils import PropertyInfo
from .._models import BaseModel

__all__ = [
    "ChatMessage",
    "ContentContentPartArray",
    "ContentContentPartArrayContentPartText",
    "ContentContentPartArrayContentPartImageURL",
    "ContentContentPartArrayContentPartImageURLImageURL",
    "ContentContentPartArrayContentPartInputAudio",
    "ContentContentPartArrayContentPartInputAudioInputAudio",
    "ContentContentPartArrayContentPartFile",
    "ContentContentPartArrayContentPartFileFile",
    "ContentContentPartArrayContentPartRefusal",
    "ToolCall",
    "ToolCallFunction",
]


class ContentContentPartArrayContentPartText(BaseModel):
    text: str

    type: Literal["text"]


class ContentContentPartArrayContentPartImageURLImageURL(BaseModel):
    url: str
    """URL or base64 image data"""

    detail: Optional[Literal["auto", "low", "high"]] = None


class ContentContentPartArrayContentPartImageURL(BaseModel):
    image_url: ContentContentPartArrayContentPartImageURLImageURL

    type: Literal["image_url"]


class ContentContentPartArrayContentPartInputAudioInputAudio(BaseModel):
    data: str
    """Base64 encoded audio data"""

    format: Literal["wav", "mp3"]


class ContentContentPartArrayContentPartInputAudio(BaseModel):
    input_audio: ContentContentPartArrayContentPartInputAudioInputAudio

    type: Literal["input_audio"]


class ContentContentPartArrayContentPartFileFile(BaseModel):
    file_data: Optional[str] = None
    """Base64 encoded file data"""

    file_id: Optional[str] = None

    filename: Optional[str] = None


class ContentContentPartArrayContentPartFile(BaseModel):
    file: ContentContentPartArrayContentPartFileFile

    type: Literal["file"]


class ContentContentPartArrayContentPartRefusal(BaseModel):
    refusal: str

    type: Literal["refusal"]


ContentContentPartArray: TypeAlias = Annotated[
    Union[
        ContentContentPartArrayContentPartText,
        ContentContentPartArrayContentPartImageURL,
        ContentContentPartArrayContentPartInputAudio,
        ContentContentPartArrayContentPartFile,
        ContentContentPartArrayContentPartRefusal,
    ],
    PropertyInfo(discriminator="type"),
]


class ToolCallFunction(BaseModel):
    arguments: str

    name: str


class ToolCall(BaseModel):
    id: str

    function: ToolCallFunction

    type: Literal["function"]


class ChatMessage(BaseModel):
    content: Union[str, List[ContentContentPartArray], None] = None
    """Message content.

    String, array of content parts (multimodal), or null when tool_calls present.
    """

    role: Literal["developer", "system", "user", "assistant", "tool"]
    """Message role"""

    name: Optional[str] = None
    """Optional participant name"""

    tool_call_id: Optional[str] = None
    """Tool call ID (required when role is "tool")"""

    tool_calls: Optional[List[ToolCall]] = None
    """Tool calls (assistant role only)"""
