# generated by datamodel-codegen:
#   filename:  execution-results.json
#   timestamp: 2026-01-25T13:38:26+00:00

from __future__ import annotations

from typing import Annotated, Any

from pydantic import BaseModel, ConfigDict, Field


class ActionResult(BaseModel):
    """
    Result of executing an action
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    node_id: str
    """
    Action node ID
    """
    action_type: str
    """
    Type of action executed
    """
    config: dict[str, Any]
    """
    Action configuration used
    """
    start_time: int
    """
    Start timestamp in milliseconds
    """
    end_time: int
    """
    End timestamp in milliseconds
    """
    duration_seconds: Annotated[float, Field(ge=0.0)]
    """
    Duration in seconds
    """
    success: bool
    """
    Whether the action succeeded
    """
    message: str
    """
    Result message
    """
    error: str | None = None
    """
    Error message if failed
    """
    screenshot: str | None = None
    """
    Screenshot reference (legacy base64 or mediaId:<id>)
    """
    screenshot_media_id: str | None = None
    """
    Server media key for uploaded screenshot
    """
    data: dict[str, Any] | None = None
    """
    Additional action-specific data
    """


class Parameters(BaseModel):
    """
    Parameters used during execution (input/output)
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    input: list[dict[str, Any]] | None = []
    output: list[dict[str, Any]] | None = []
    parameterBefore: list[dict[str, Any]] | None = []
    variableBefore: list[dict[str, Any]] | None = []


class BrowserInfo(BaseModel):
    """
    Browser information
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    name: str | None = None
    version: str | None = None
    user_agent: str | None = None


class PerformanceMetrics(BaseModel):
    """
    Performance metrics collected during execution
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    total_actions: Annotated[int | None, Field(ge=0)] = None
    successful_actions: Annotated[int | None, Field(ge=0)] = None
    failed_actions: Annotated[int | None, Field(ge=0)] = None
    average_action_time: Annotated[float | None, Field(ge=0.0)] = None
    total_network_requests: Annotated[int | None, Field(ge=0)] = None
    total_data_transferred: Annotated[int | None, Field(ge=0)] = None


class FlowReport(BaseModel):
    """
    Complete report of flow execution
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    actions: list[ActionResult]
    """
    Results of all actions
    """
    variables: dict[str, list[dict[str, Any]]]
    """
    Variables used during execution (input/output)
    """
    parameters: Annotated[
        Parameters,
        Field(
            default_factory=lambda: Parameters.model_validate(
                {'input': [], 'output': [], 'parameterBefore': [], 'variableBefore': []}
            )
        ),
    ]
    """
    Parameters used during execution (input/output)
    """
    output: dict[str, Any]
    """
    Final output
    """
    recording: str | None = None
    """
    Recording data (deprecated, use recording_file instead)
    """
    recording_file: str | None = None
    """
    Path to the recording file on the server
    """
    recording_duration: Annotated[float | None, Field(ge=0.0)] = None
    """
    Duration of the recording in seconds
    """
    flow_id: str | None = None
    """
    ID of the executed flow
    """
    flow_name: str | None = None
    """
    Name of the executed flow
    """
    start_time: int | None = None
    """
    Flow execution start timestamp
    """
    end_time: int | None = None
    """
    Flow execution end timestamp
    """
    total_duration: Annotated[float | None, Field(ge=0.0)] = None
    """
    Total execution time in seconds
    """
    success: bool | None = None
    """
    Overall flow success status
    """
    error: str | None = None
    """
    Error message if flow failed
    """
    environment: dict[str, Any] | None = None
    """
    Environment used during execution
    """
    browser_info: BrowserInfo | None = None
    """
    Browser information
    """
    run_config: dict[str, Any] | None = None
    """
    Runtime execution configuration
    """
    performance_metrics: PerformanceMetrics | None = None
    """
    Performance metrics collected during execution
    """


class ExecutionResults(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    actionResults: list[ActionResult] | None = None
    flowReports: list[FlowReport] | None = None


class ExecutionResultsModels(BaseModel):
    """
    Schema for action execution results and flow reports
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    executionResults: ExecutionResults | None = None
