"""The top-level event type representing an event in a conversation.

This is the root container for all other event subtypes (conversation start,
exchanges, messages, content, citations, tool calls, and async streams).
"""

from pydantic import BaseModel, ConfigDict, Field

from .async_stream import UiPathConversationAsyncInputStreamEvent
from .error import UiPathConversationErrorEvent
from .exchange import UiPathConversationExchangeEvent
from .meta import UiPathConversationMetaEvent
from .session import (
    UiPathSessionEndEvent,
    UiPathSessionEndingEvent,
    UiPathSessionStartedEvent,
    UiPathSessionStartEvent,
)
from .tool import UiPathConversationToolCallEvent


class UiPathConversationLabelUpdatedEvent(BaseModel):
    """Indicates the update of the conversation label."""

    label: str
    autogenerated: bool

    model_config = ConfigDict(validate_by_name=True, validate_by_alias=True)


class UiPathConversationEvent(BaseModel):
    """The top-level event type representing an event in a conversation.

    This is the root container for all other event subtypes (conversation start,
    exchanges, messages, content, citations, tool calls, and async streams).
    """

    conversation_id: str = Field(
        ...,
        alias="conversationId",
        description="A globally unique identifier for conversation to which the other sub-event and data properties apply.",
    )
    start: UiPathSessionStartEvent | None = Field(
        None,
        alias="startSession",
        description="Signals the start of session for a conversation.",
    )
    started: UiPathSessionStartedEvent | None = Field(
        None,
        alias="sessionStarted",
        description="Sent in response to a SessionStartEvent to signal the acceptance of the session.",
    )
    ending: UiPathSessionEndingEvent | None = Field(
        None,
        alias="sessionEnding",
        description="Sent by the service when the client needs to end the current session.",
    )
    end: UiPathSessionEndEvent | None = Field(
        None,
        alias="endSession",
        description="Signals the end of a session for a conversation.",
    )
    exchange: UiPathConversationExchangeEvent | None = Field(
        None,
        description="Encapsulates sub-events related to an exchange within a conversation.",
    )
    async_input_stream: UiPathConversationAsyncInputStreamEvent | None = Field(
        None,
        alias="asyncInputStream",
        description="Encapsulates sub-events related to an asynchronous input stream.",
    )
    async_tool_call: UiPathConversationToolCallEvent | None = Field(
        None,
        alias="asyncToolCall",
        description="Optional async tool call sub-event. This feature is not supported by all LLMs. Most tool calls are scoped to a message, and use the toolCall and toolResult properties defined by the ConversationMessage type.",
    )
    label_updated: "UiPathConversationLabelUpdatedEvent | None" = Field(
        None,
        alias="labelUpdated",
        description="Indicates that the conversation's label has been updated. Useful for UIs to update the display name of live conversations.",
    )
    meta_event: UiPathConversationMetaEvent | None = Field(
        None,
        alias="metaEvent",
        description="Allows additional events to be sent in the context of the enclosing event stream.",
    )
    error: UiPathConversationErrorEvent | None = Field(
        None,
        alias="conversationError",
        description="Sent by the service to indicate the start and end of an error condition impacting a conversation. The client should not send any events for this conversation while the error condition is present.",
    )

    model_config = ConfigDict(validate_by_name=True, validate_by_alias=True)
