"""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 ToolResultContent


@dataclass(kw_only=True)
class ToolSpec:
    """Declaration of a tool the model can call."""
    name: str
    description: str
    input_schema: str


@dataclass(kw_only=True)
class AgentAsToolConfig:
    """Wrap a configured agent as a tool callable by the parent agent. The
child agent is instantiated at registration time."""
    name: str | None
    description: str | None
    preserve_context: bool
    agent_config: str


@dataclass(kw_only=True)
class CallToolArgs:
    """Arguments for a single tool call."""
    name: str
    input: str
    tool_use_id: str


class ToolChoice:
    """Policy controlling whether and how the model calls tools on the next
generation step."""
    if TYPE_CHECKING:
        Auto: ClassVar[type["_ToolChoice_Auto"]]
        Any: ClassVar[type["_ToolChoice_Any"]]
        Named: ClassVar[type["_ToolChoice_Named"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "ToolChoice": ...

class _ToolChoice_Auto(_WitVariantCase, ToolChoice):
    """Model decides whether to call a tool."""
    tag = 'auto'
ToolChoice.Auto = _ToolChoice_Auto  # type: ignore[attr-defined]

class _ToolChoice_Any(_WitVariantCase, ToolChoice):
    """Model must call at least one tool."""
    tag = 'any'
ToolChoice.Any = _ToolChoice_Any  # type: ignore[attr-defined]

class _ToolChoice_Named(_WitVariantCase, ToolChoice):
    """Model must call the tool with this name."""
    tag = 'named'
ToolChoice.Named = _ToolChoice_Named  # type: ignore[attr-defined]

ToolChoice._CASES = {  # type: ignore[attr-defined]
    'auto': ToolChoice.Auto,
    'any': ToolChoice.Any,
    'named': ToolChoice.Named,
}


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

class ToolEventStream:
    """Pull-based stream of tool events. Sync-WIT placeholder for
`stream<tool-stream-event>`."""
    # Wraps a wasmtime-py ResourceAny / ResourceHost handle.
    # The runtime sets ._handle to the underlying resource and
    # ._invoke to a callable that dispatches a method by WIT name.

    def __init__(self, handle: Any, invoke: Any = None) -> None:
        self._handle = handle
        self._invoke = invoke

    def read(self) -> ToolStreamEvent | None:
        return self._invoke('[method]tool-event-stream.read', (self._handle,))


class ToolError:
    """Why a tool call failed."""
    if TYPE_CHECKING:
        Unknown: ClassVar[type["_ToolError_Unknown"]]
        InvalidInput: ClassVar[type["_ToolError_InvalidInput"]]
        ExecutionFailed: ClassVar[type["_ToolError_ExecutionFailed"]]
        TimedOut: ClassVar[type["_ToolError_TimedOut"]]
        Cancelled: ClassVar[type["_ToolError_Cancelled"]]
        Internal: ClassVar[type["_ToolError_Internal"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "ToolError": ...

class _ToolError_Unknown(_WitVariantCase, ToolError):
    """No tool registered under the given name."""
    tag = 'unknown'
ToolError.Unknown = _ToolError_Unknown  # type: ignore[attr-defined]

class _ToolError_InvalidInput(_WitVariantCase, ToolError):
    """Tool input didn't match the declared input schema."""
    tag = 'invalid-input'
ToolError.InvalidInput = _ToolError_InvalidInput  # type: ignore[attr-defined]

class _ToolError_ExecutionFailed(_WitVariantCase, ToolError):
    """Tool ran but returned an error result."""
    tag = 'execution-failed'
ToolError.ExecutionFailed = _ToolError_ExecutionFailed  # type: ignore[attr-defined]

class _ToolError_TimedOut(_WitVariantCase, ToolError):
    """Tool exceeded its time budget."""
    tag = 'timed-out'
ToolError.TimedOut = _ToolError_TimedOut  # type: ignore[attr-defined]

class _ToolError_Cancelled(_WitVariantCase, ToolError):
    """Tool was cancelled before completion."""
    tag = 'cancelled'
ToolError.Cancelled = _ToolError_Cancelled  # type: ignore[attr-defined]

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

ToolError._CASES = {  # type: ignore[attr-defined]
    'unknown': ToolError.Unknown,
    'invalid-input': ToolError.InvalidInput,
    'execution-failed': ToolError.ExecutionFailed,
    'timed-out': ToolError.TimedOut,
    'cancelled': ToolError.Cancelled,
    'internal': ToolError.Internal,
}


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

ToolStreamEvent = str | list[ToolResultContent] | ToolError
"""Incremental event emitted by a streaming tool while running."""
