"""Domain models for CleverAgents - auto-generated from Phase 0 stubs."""

from datetime import datetime
from enum import StrEnum

from pydantic import BaseModel, ConfigDict, Field

# Import ApiError from auth module
from ..auth.auth import ApiError


class StreamMessageType(StrEnum):
    """Enum for stream message types."""

    INFO = "info"
    ERROR = "error"
    BUILD = "build"
    REPLY = "reply"
    DESCRIPTION = "description"
    FINISHED = "finished"


class ConvoMessageDescription(BaseModel):
    """Data contract for ConvoMessageDescription."""

    message_id: str = Field(..., alias="messageId")
    role: str = Field(...)
    content: str = Field(...)
    timestamp: datetime = Field(...)

    model_config = ConfigDict(
        str_strip_whitespace=True,
        validate_assignment=True,
        arbitrary_types_allowed=False,
        populate_by_name=True,
        use_enum_values=True,
    )


class BuildInfo(BaseModel):
    """Data contract for BuildInfo."""

    path: str = Field(...)
    num_tokens: int = Field(..., alias="numTokens")
    finished: bool = Field(...)
    removed: bool | None = Field(default=None)

    model_config = ConfigDict(
        str_strip_whitespace=True,
        validate_assignment=True,
        arbitrary_types_allowed=False,
        populate_by_name=True,
        use_enum_values=True,
    )


class StreamMessage(BaseModel):
    """Data contract for StreamMessage."""

    type_: StreamMessageType = Field(...)
    reply_chunk: str | None = Field(alias="replyChunk", default=None)
    build_info: BuildInfo | None = Field(alias="buildInfo", default=None)
    description: ConvoMessageDescription | None = Field(default=None)
    error: ApiError | None = Field(default=None)
    missing_file_path: str | None = Field(alias="missingFilePath", default=None)
    missing_file_auto_context: bool | None = Field(
        alias="missingFileAutoContext", default=None
    )
    model_stream_id: str | None = Field(alias="modelStreamId", default=None)
    load_context_files: list[str] | None = Field(alias="loadContextFiles", default=None)
    init_prompt: str | None = Field(alias="initPrompt", default=None)
    init_replies: list[str] | None = Field(alias="initReplies", default=None)
    init_build_only: bool | None = Field(alias="initBuildOnly", default=None)
    stream_messages: list["StreamMessage"] | None = Field(
        alias="streamMessages", default=None
    )

    model_config = ConfigDict(
        str_strip_whitespace=True,
        validate_assignment=True,
        arbitrary_types_allowed=False,
        populate_by_name=True,
        use_enum_values=True,
    )
