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

from __future__ import annotations

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .file_info import FileInfo
from .run_status import RunStatus
from .script_run_response import ScriptRunResponse
from .task_run_request import TaskRunRequest
from .task_run_response_output import TaskRunResponseOutput
from .workflow_run_request import WorkflowRunRequest
from .workflow_run_response_output import WorkflowRunResponseOutput


class GetRunResponse_TaskV1(UniversalBaseModel):
    run_type: typing.Literal["task_v1"] = "task_v1"
    run_id: str
    status: RunStatus
    output: typing.Optional[TaskRunResponseOutput] = None
    downloaded_files: typing.Optional[typing.List[FileInfo]] = None
    recording_url: typing.Optional[str] = None
    screenshot_urls: typing.Optional[typing.List[str]] = None
    failure_reason: typing.Optional[str] = None
    created_at: dt.datetime
    modified_at: dt.datetime
    queued_at: typing.Optional[dt.datetime] = None
    started_at: typing.Optional[dt.datetime] = None
    finished_at: typing.Optional[dt.datetime] = None
    app_url: typing.Optional[str] = None
    browser_session_id: typing.Optional[str] = None
    browser_profile_id: typing.Optional[str] = None
    max_screenshot_scrolls: typing.Optional[int] = None
    script_run: typing.Optional[ScriptRunResponse] = None
    errors: typing.Optional[typing.List[typing.Dict[str, typing.Optional[typing.Any]]]] = None
    step_count: typing.Optional[int] = None
    run_request: typing.Optional[TaskRunRequest] = 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


class GetRunResponse_TaskV2(UniversalBaseModel):
    run_type: typing.Literal["task_v2"] = "task_v2"
    run_id: str
    status: RunStatus
    output: typing.Optional[TaskRunResponseOutput] = None
    downloaded_files: typing.Optional[typing.List[FileInfo]] = None
    recording_url: typing.Optional[str] = None
    screenshot_urls: typing.Optional[typing.List[str]] = None
    failure_reason: typing.Optional[str] = None
    created_at: dt.datetime
    modified_at: dt.datetime
    queued_at: typing.Optional[dt.datetime] = None
    started_at: typing.Optional[dt.datetime] = None
    finished_at: typing.Optional[dt.datetime] = None
    app_url: typing.Optional[str] = None
    browser_session_id: typing.Optional[str] = None
    browser_profile_id: typing.Optional[str] = None
    max_screenshot_scrolls: typing.Optional[int] = None
    script_run: typing.Optional[ScriptRunResponse] = None
    errors: typing.Optional[typing.List[typing.Dict[str, typing.Optional[typing.Any]]]] = None
    step_count: typing.Optional[int] = None
    run_request: typing.Optional[TaskRunRequest] = 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


class GetRunResponse_OpenaiCua(UniversalBaseModel):
    run_type: typing.Literal["openai_cua"] = "openai_cua"
    run_id: str
    status: RunStatus
    output: typing.Optional[TaskRunResponseOutput] = None
    downloaded_files: typing.Optional[typing.List[FileInfo]] = None
    recording_url: typing.Optional[str] = None
    screenshot_urls: typing.Optional[typing.List[str]] = None
    failure_reason: typing.Optional[str] = None
    created_at: dt.datetime
    modified_at: dt.datetime
    queued_at: typing.Optional[dt.datetime] = None
    started_at: typing.Optional[dt.datetime] = None
    finished_at: typing.Optional[dt.datetime] = None
    app_url: typing.Optional[str] = None
    browser_session_id: typing.Optional[str] = None
    browser_profile_id: typing.Optional[str] = None
    max_screenshot_scrolls: typing.Optional[int] = None
    script_run: typing.Optional[ScriptRunResponse] = None
    errors: typing.Optional[typing.List[typing.Dict[str, typing.Optional[typing.Any]]]] = None
    step_count: typing.Optional[int] = None
    run_request: typing.Optional[TaskRunRequest] = 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


class GetRunResponse_AnthropicCua(UniversalBaseModel):
    run_type: typing.Literal["anthropic_cua"] = "anthropic_cua"
    run_id: str
    status: RunStatus
    output: typing.Optional[TaskRunResponseOutput] = None
    downloaded_files: typing.Optional[typing.List[FileInfo]] = None
    recording_url: typing.Optional[str] = None
    screenshot_urls: typing.Optional[typing.List[str]] = None
    failure_reason: typing.Optional[str] = None
    created_at: dt.datetime
    modified_at: dt.datetime
    queued_at: typing.Optional[dt.datetime] = None
    started_at: typing.Optional[dt.datetime] = None
    finished_at: typing.Optional[dt.datetime] = None
    app_url: typing.Optional[str] = None
    browser_session_id: typing.Optional[str] = None
    browser_profile_id: typing.Optional[str] = None
    max_screenshot_scrolls: typing.Optional[int] = None
    script_run: typing.Optional[ScriptRunResponse] = None
    errors: typing.Optional[typing.List[typing.Dict[str, typing.Optional[typing.Any]]]] = None
    step_count: typing.Optional[int] = None
    run_request: typing.Optional[TaskRunRequest] = 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


class GetRunResponse_UiTars(UniversalBaseModel):
    run_type: typing.Literal["ui_tars"] = "ui_tars"
    run_id: str
    status: RunStatus
    output: typing.Optional[TaskRunResponseOutput] = None
    downloaded_files: typing.Optional[typing.List[FileInfo]] = None
    recording_url: typing.Optional[str] = None
    screenshot_urls: typing.Optional[typing.List[str]] = None
    failure_reason: typing.Optional[str] = None
    created_at: dt.datetime
    modified_at: dt.datetime
    queued_at: typing.Optional[dt.datetime] = None
    started_at: typing.Optional[dt.datetime] = None
    finished_at: typing.Optional[dt.datetime] = None
    app_url: typing.Optional[str] = None
    browser_session_id: typing.Optional[str] = None
    browser_profile_id: typing.Optional[str] = None
    max_screenshot_scrolls: typing.Optional[int] = None
    script_run: typing.Optional[ScriptRunResponse] = None
    errors: typing.Optional[typing.List[typing.Dict[str, typing.Optional[typing.Any]]]] = None
    step_count: typing.Optional[int] = None
    run_request: typing.Optional[TaskRunRequest] = 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


class GetRunResponse_WorkflowRun(UniversalBaseModel):
    run_type: typing.Literal["workflow_run"] = "workflow_run"
    run_id: str
    status: RunStatus
    output: typing.Optional[WorkflowRunResponseOutput] = None
    downloaded_files: typing.Optional[typing.List[FileInfo]] = None
    recording_url: typing.Optional[str] = None
    screenshot_urls: typing.Optional[typing.List[str]] = None
    failure_reason: typing.Optional[str] = None
    created_at: dt.datetime
    modified_at: dt.datetime
    queued_at: typing.Optional[dt.datetime] = None
    started_at: typing.Optional[dt.datetime] = None
    finished_at: typing.Optional[dt.datetime] = None
    app_url: typing.Optional[str] = None
    browser_session_id: typing.Optional[str] = None
    browser_profile_id: typing.Optional[str] = None
    max_screenshot_scrolls: typing.Optional[int] = None
    script_run: typing.Optional[ScriptRunResponse] = None
    errors: typing.Optional[typing.List[typing.Dict[str, typing.Optional[typing.Any]]]] = None
    step_count: typing.Optional[int] = None
    run_with: typing.Optional[str] = None
    ai_fallback: typing.Optional[bool] = None
    run_request: typing.Optional[WorkflowRunRequest] = 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


GetRunResponse = typing.Union[
    GetRunResponse_TaskV1,
    GetRunResponse_TaskV2,
    GetRunResponse_OpenaiCua,
    GetRunResponse_AnthropicCua,
    GetRunResponse_UiTars,
    GetRunResponse_WorkflowRun,
]
