"""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, Optional, 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."""

    class Agent(_WitVariantCase):
        """Wraps a single agent."""
        tag = 'agent'

    class MultiAgent(_WitVariantCase):
        """Wraps a nested orchestrator."""
        tag = 'multi-agent'

    _CASES: dict[str, type] = {
        'agent': Agent,
        'multi-agent': MultiAgent,
    }

    @staticmethod
    def lift(raw: _WitVariant) -> NodeConfig:
        cls = NodeConfig._CASES.get(raw.tag)
        if cls is None:
            raise ValueError(f'unknown NodeConfig arm: {raw.tag!r}')
        return cls(raw.payload)

@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."""

    class Execution(_WitVariantCase):
        """An underlying agent or nested orchestrator failed."""
        tag = 'execution'

    class Timeout(_WitVariantCase):
        """Wall-clock ceiling was exceeded."""
        tag = 'timeout'

    class LimitExceeded(_WitVariantCase):
        """A declared runtime limit (max-steps, max-concurrency) was hit."""
        tag = 'limit-exceeded'

    class EdgeHandler(_WitVariantCase):
        """Edge handler rejected the traversal with an error."""
        tag = 'edge-handler'

    class InvalidConfig(_WitVariantCase):
        """Invalid configuration detected at run time."""
        tag = 'invalid-config'

    class Internal(_WitVariantCase):
        """Catch-all for internal failures."""
        tag = 'internal'

    _CASES: dict[str, type] = {
        'execution': Execution,
        'timeout': Timeout,
        'limit-exceeded': LimitExceeded,
        'edge-handler': EdgeHandler,
        'invalid-config': InvalidConfig,
        'internal': Internal,
    }

    @staticmethod
    def lift(raw: _WitVariant) -> NodeError:
        cls = NodeError._CASES.get(raw.tag)
        if cls is None:
            raise ValueError(f'unknown NodeError arm: {raw.tag!r}')
        return cls(raw.payload)

@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."""

    class NodeStart(_WitVariantCase):
        """A node began executing."""
        tag = 'node-start'

    class Nested(_WitVariantCase):
        """A nested stream event from a running node."""
        tag = 'nested'

    class NodeStop(_WitVariantCase):
        """A node finished executing."""
        tag = 'node-stop'

    class Handoff(_WitVariantCase):
        """A handoff happened between nodes."""
        tag = 'handoff'

    class RunComplete(_WitVariantCase):
        """Terminal result for the run."""
        tag = 'run-complete'

    _CASES: dict[str, type] = {
        'node-start': NodeStart,
        'nested': Nested,
        'node-stop': NodeStop,
        'handoff': Handoff,
        'run-complete': RunComplete,
    }

    @staticmethod
    def lift(raw: _WitVariant) -> MultiAgentStreamEvent:
        cls = MultiAgentStreamEvent._CASES.get(raw.tag)
        if cls is None:
            raise ValueError(f'unknown MultiAgentStreamEvent arm: {raw.tag!r}')
        return cls(raw.payload)
