# This file was auto-generated by Fern from our API Definition.

from __future__ import annotations

import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel


class LogStreamEvent_Connected(UniversalBaseModel):
    """
    Union of all possible log stream SSE events.

    Use the 'type' field to discriminate between event types:
    - "connected": Stream connection established
    - "log": A log entry
    - "error": An error occurred in the stream
    """

    type: typing.Literal["connected"] = "connected"
    agent_id: str

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow


class LogStreamEvent_Error(UniversalBaseModel):
    """
    Union of all possible log stream SSE events.

    Use the 'type' field to discriminate between event types:
    - "connected": Stream connection established
    - "log": A log entry
    - "error": An error occurred in the stream
    """

    type: typing.Literal["error"] = "error"
    message: str

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow


class LogStreamEvent_Log(UniversalBaseModel):
    """
    Union of all possible log stream SSE events.

    Use the 'type' field to discriminate between event types:
    - "connected": Stream connection established
    - "log": A log entry
    - "error": An error occurred in the stream
    """

    type: typing.Literal["log"] = "log"
    agent_id: str
    branch_id: typing.Optional[str] = None
    environment: typing.Optional[str] = None
    level: str
    log_id: str
    logger: typing.Optional[str] = None
    message: str
    source: str
    task_id: typing.Optional[str] = None
    timestamp: str
    version: typing.Optional[str] = None

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow


LogStreamEvent = typing_extensions.Annotated[
    typing.Union[LogStreamEvent_Connected, LogStreamEvent_Error, LogStreamEvent_Log],
    pydantic.Field(discriminator="type"),
]
