"""Auto-generated by bindgen. Do not edit."""
# ruff: noqa: E501, F401, I001
# fmt: off

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, ClassVar, Optional, TYPE_CHECKING, Union

from wasmtime.component import Variant as _WitVariant
from wasmtime.component import VariantCase as _WitVariantCase

from .messages import ContentBlock, Metrics, PromptInput, Usage
from .streaming import StreamEvent


Duration = int

class OrchestrationStatus(str):
    """Lifecycle status of a node or overall run."""
    __slots__ = ()

    PENDING: OrchestrationStatus
    EXECUTING: OrchestrationStatus
    COMPLETED: OrchestrationStatus
    FAILED: OrchestrationStatus
    CANCELLED: OrchestrationStatus

OrchestrationStatus.PENDING = OrchestrationStatus('pending')  # type: ignore[attr-defined]
OrchestrationStatus.EXECUTING = OrchestrationStatus('executing')  # type: ignore[attr-defined]
OrchestrationStatus.COMPLETED = OrchestrationStatus('completed')  # type: ignore[attr-defined]
OrchestrationStatus.FAILED = OrchestrationStatus('failed')  # type: ignore[attr-defined]
OrchestrationStatus.CANCELLED = OrchestrationStatus('cancelled')  # type: ignore[attr-defined]


class TerminalStatus(str):
    """Terminal status of a node or run."""
    __slots__ = ()

    COMPLETED: TerminalStatus
    FAILED: TerminalStatus
    CANCELLED: TerminalStatus

TerminalStatus.COMPLETED = TerminalStatus('completed')  # type: ignore[attr-defined]
TerminalStatus.FAILED = TerminalStatus('failed')  # type: ignore[attr-defined]
TerminalStatus.CANCELLED = TerminalStatus('cancelled')  # type: ignore[attr-defined]


class NodeKind(str):
    """What a node is."""
    __slots__ = ()

    AGENT: NodeKind
    MULTI_AGENT: NodeKind

NodeKind.AGENT = NodeKind('agent')  # type: ignore[attr-defined]
NodeKind.MULTI_AGENT = NodeKind('multi-agent')  # type: ignore[attr-defined]


@dataclass(kw_only=True)
class AgentNode:
    """Definition of an agent-backed node."""
    id: str
    description: str | None
    timeout: int | None
    agent_config: str


@dataclass(kw_only=True)
class MultiAgentNode:
    """Definition of a node that wraps another orchestrator."""
    id: str
    description: str | None
    orchestrator: str


class NodeConfig:
    """Any node a graph or swarm can execute."""
    if TYPE_CHECKING:
        Agent: ClassVar[type["_NodeConfig_Agent"]]
        MultiAgent: ClassVar[type["_NodeConfig_MultiAgent"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "NodeConfig": ...

class _NodeConfig_Agent(_WitVariantCase, NodeConfig):
    """Wraps a single agent."""
    tag = 'agent'
NodeConfig.Agent = _NodeConfig_Agent  # type: ignore[attr-defined]

class _NodeConfig_MultiAgent(_WitVariantCase, NodeConfig):
    """Wraps a nested orchestrator."""
    tag = 'multi-agent'
NodeConfig.MultiAgent = _NodeConfig_MultiAgent  # type: ignore[attr-defined]

NodeConfig._CASES = {  # type: ignore[attr-defined]
    'agent': NodeConfig.Agent,
    'multi-agent': NodeConfig.MultiAgent,
}


def _NodeConfig_lift(raw: _WitVariant) -> NodeConfig:
    cls = NodeConfig._CASES.get(raw.tag)  # type: ignore[attr-defined]
    if cls is None:
        raise ValueError(f'unknown NodeConfig arm: {raw.tag!r}')
    return cls(raw.payload)
NodeConfig.lift = staticmethod(_NodeConfig_lift)  # type: ignore[attr-defined]

@dataclass(kw_only=True)
class EdgeHandler:
    """Condition attached to a graph edge."""
    handler_id: str


@dataclass(kw_only=True)
class EdgeConfig:
    """Edge connecting two graph nodes."""
    source: str
    target: str
    handler: EdgeHandler | None


@dataclass(kw_only=True)
class GraphConfig:
    """Runtime configuration for a Graph."""
    id: str
    nodes: list[NodeConfig]
    edges: list[EdgeConfig]
    sources: list[str]
    max_concurrency: int | None
    max_steps: int | None
    timeout: int | None
    node_timeout: int | None


@dataclass(kw_only=True)
class SwarmConfig:
    """Runtime configuration for a Swarm."""
    id: str
    nodes: list[AgentNode]
    start_node_id: str
    max_steps: int | None
    timeout: int | None
    node_timeout: int | None


class NodeError:
    """Why a node or run ended in `failed` status."""
    if TYPE_CHECKING:
        Execution: ClassVar[type["_NodeError_Execution"]]
        Timeout: ClassVar[type["_NodeError_Timeout"]]
        LimitExceeded: ClassVar[type["_NodeError_LimitExceeded"]]
        EdgeHandler: ClassVar[type["_NodeError_EdgeHandler"]]
        InvalidConfig: ClassVar[type["_NodeError_InvalidConfig"]]
        Internal: ClassVar[type["_NodeError_Internal"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "NodeError": ...

class _NodeError_Execution(_WitVariantCase, NodeError):
    """An underlying agent or nested orchestrator failed."""
    tag = 'execution'
NodeError.Execution = _NodeError_Execution  # type: ignore[attr-defined]

class _NodeError_Timeout(_WitVariantCase, NodeError):
    """Wall-clock ceiling was exceeded."""
    tag = 'timeout'
NodeError.Timeout = _NodeError_Timeout  # type: ignore[attr-defined]

class _NodeError_LimitExceeded(_WitVariantCase, NodeError):
    """A declared runtime limit (max-steps, max-concurrency) was hit."""
    tag = 'limit-exceeded'
NodeError.LimitExceeded = _NodeError_LimitExceeded  # type: ignore[attr-defined]

class _NodeError_EdgeHandler(_WitVariantCase, NodeError):
    """Edge handler rejected the traversal with an error."""
    tag = 'edge-handler'
NodeError.EdgeHandler = _NodeError_EdgeHandler  # type: ignore[attr-defined]

class _NodeError_InvalidConfig(_WitVariantCase, NodeError):
    """Invalid configuration detected at run time."""
    tag = 'invalid-config'
NodeError.InvalidConfig = _NodeError_InvalidConfig  # type: ignore[attr-defined]

class _NodeError_Internal(_WitVariantCase, NodeError):
    """Catch-all for internal failures."""
    tag = 'internal'
NodeError.Internal = _NodeError_Internal  # type: ignore[attr-defined]

NodeError._CASES = {  # type: ignore[attr-defined]
    'execution': NodeError.Execution,
    'timeout': NodeError.Timeout,
    'limit-exceeded': NodeError.LimitExceeded,
    'edge-handler': NodeError.EdgeHandler,
    'invalid-config': NodeError.InvalidConfig,
    'internal': NodeError.Internal,
}


def _NodeError_lift(raw: _WitVariant) -> NodeError:
    cls = NodeError._CASES.get(raw.tag)  # type: ignore[attr-defined]
    if cls is None:
        raise ValueError(f'unknown NodeError arm: {raw.tag!r}')
    return cls(raw.payload)
NodeError.lift = staticmethod(_NodeError_lift)  # type: ignore[attr-defined]

@dataclass(kw_only=True)
class NodeResult:
    """Result of a single node execution."""
    node_id: str
    status: TerminalStatus
    duration: int
    content: list[ContentBlock]
    error: NodeError | None
    structured_output: str | None
    usage: Usage | None
    metrics: Metrics | None


@dataclass(kw_only=True)
class MultiAgentResult:
    """Final result of a graph or swarm run."""
    status: TerminalStatus
    nodes: list[NodeResult]
    duration: int
    usage: Usage | None
    metrics: Metrics | None


@dataclass(kw_only=True)
class MultiAgentInvokeArgs:
    """Arguments for invoking a graph or swarm."""
    input: PromptInput
    invocation_state: str | None


@dataclass(kw_only=True)
class NodeStartData:
    """Payload for `node-start`."""
    node_id: str
    kind: NodeKind


@dataclass(kw_only=True)
class NodeEventData:
    """Payload for `node-event`. Carries a nested stream event from a
running node."""
    node_id: str
    event: StreamEvent


@dataclass(kw_only=True)
class HandoffEvent:
    """Payload for a handoff edge firing."""
    from_node_ids: list[str]
    to_node_ids: list[str]


class MultiAgentStreamEvent:
    """Events emitted while streaming a multi-agent run."""
    if TYPE_CHECKING:
        NodeStart: ClassVar[type["_MultiAgentStreamEvent_NodeStart"]]
        Nested: ClassVar[type["_MultiAgentStreamEvent_Nested"]]
        NodeStop: ClassVar[type["_MultiAgentStreamEvent_NodeStop"]]
        Handoff: ClassVar[type["_MultiAgentStreamEvent_Handoff"]]
        RunComplete: ClassVar[type["_MultiAgentStreamEvent_RunComplete"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "MultiAgentStreamEvent": ...

class _MultiAgentStreamEvent_NodeStart(_WitVariantCase, MultiAgentStreamEvent):
    """A node began executing."""
    tag = 'node-start'
MultiAgentStreamEvent.NodeStart = _MultiAgentStreamEvent_NodeStart  # type: ignore[attr-defined]

class _MultiAgentStreamEvent_Nested(_WitVariantCase, MultiAgentStreamEvent):
    """A nested stream event from a running node."""
    tag = 'nested'
MultiAgentStreamEvent.Nested = _MultiAgentStreamEvent_Nested  # type: ignore[attr-defined]

class _MultiAgentStreamEvent_NodeStop(_WitVariantCase, MultiAgentStreamEvent):
    """A node finished executing."""
    tag = 'node-stop'
MultiAgentStreamEvent.NodeStop = _MultiAgentStreamEvent_NodeStop  # type: ignore[attr-defined]

class _MultiAgentStreamEvent_Handoff(_WitVariantCase, MultiAgentStreamEvent):
    """A handoff happened between nodes."""
    tag = 'handoff'
MultiAgentStreamEvent.Handoff = _MultiAgentStreamEvent_Handoff  # type: ignore[attr-defined]

class _MultiAgentStreamEvent_RunComplete(_WitVariantCase, MultiAgentStreamEvent):
    """Terminal result for the run."""
    tag = 'run-complete'
MultiAgentStreamEvent.RunComplete = _MultiAgentStreamEvent_RunComplete  # type: ignore[attr-defined]

MultiAgentStreamEvent._CASES = {  # type: ignore[attr-defined]
    'node-start': MultiAgentStreamEvent.NodeStart,
    'nested': MultiAgentStreamEvent.Nested,
    'node-stop': MultiAgentStreamEvent.NodeStop,
    'handoff': MultiAgentStreamEvent.Handoff,
    'run-complete': MultiAgentStreamEvent.RunComplete,
}


def _MultiAgentStreamEvent_lift(raw: _WitVariant) -> MultiAgentStreamEvent:
    cls = MultiAgentStreamEvent._CASES.get(raw.tag)  # type: ignore[attr-defined]
    if cls is None:
        raise ValueError(f'unknown MultiAgentStreamEvent arm: {raw.tag!r}')
    return cls(raw.payload)
MultiAgentStreamEvent.lift = staticmethod(_MultiAgentStreamEvent_lift)  # type: ignore[attr-defined]
