"""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 Message
from ..wasi_clocks.wall_clock import Datetime


@dataclass(kw_only=True)
class FileStorage:
    """Local filesystem snapshot storage."""
    base_dir: str


@dataclass(kw_only=True)
class S3Storage:
    """S3 snapshot storage."""
    bucket: str
    region: str | None
    prefix: str | None


@dataclass(kw_only=True)
class CustomStorage:
    """Reference to an application-implemented storage backend."""
    backend_id: str


class StorageConfig:
    """Where to persist session snapshots."""
    if TYPE_CHECKING:
        File: ClassVar[type["_StorageConfig_File"]]
        S3: ClassVar[type["_StorageConfig_S3"]]
        Custom: ClassVar[type["_StorageConfig_Custom"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "StorageConfig": ...

class _StorageConfig_File(_WitVariantCase, StorageConfig):
    """Local filesystem."""
    tag = 'file'
StorageConfig.File = _StorageConfig_File  # type: ignore[attr-defined]

class _StorageConfig_S3(_WitVariantCase, StorageConfig):
    """Amazon S3."""
    tag = 's3'
StorageConfig.S3 = _StorageConfig_S3  # type: ignore[attr-defined]

class _StorageConfig_Custom(_WitVariantCase, StorageConfig):
    """Application-implemented backend."""
    tag = 'custom'
StorageConfig.Custom = _StorageConfig_Custom  # type: ignore[attr-defined]

StorageConfig._CASES = {  # type: ignore[attr-defined]
    'file': StorageConfig.File,
    's3': StorageConfig.S3,
    'custom': StorageConfig.Custom,
}


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

class SaveLatestPolicy:
    """When to update the "latest" snapshot pointer. The `trigger` arm
carries the id of an application-supplied callback that decides
per-invocation."""
    if TYPE_CHECKING:
        Message: ClassVar[type["_SaveLatestPolicy_Message"]]
        Invocation: ClassVar[type["_SaveLatestPolicy_Invocation"]]
        Trigger: ClassVar[type["_SaveLatestPolicy_Trigger"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "SaveLatestPolicy": ...

class _SaveLatestPolicy_Message(_WitVariantCase, SaveLatestPolicy):
    """After every message added to the conversation."""
    tag = 'message'
SaveLatestPolicy.Message = _SaveLatestPolicy_Message  # type: ignore[attr-defined]

class _SaveLatestPolicy_Invocation(_WitVariantCase, SaveLatestPolicy):
    """Once per invocation, after it completes."""
    tag = 'invocation'
SaveLatestPolicy.Invocation = _SaveLatestPolicy_Invocation  # type: ignore[attr-defined]

class _SaveLatestPolicy_Trigger(_WitVariantCase, SaveLatestPolicy):
    """Each invocation consults the named `snapshot-trigger-handler`.
The id identifies which handler to invoke."""
    tag = 'trigger'
SaveLatestPolicy.Trigger = _SaveLatestPolicy_Trigger  # type: ignore[attr-defined]

SaveLatestPolicy._CASES = {  # type: ignore[attr-defined]
    'message': SaveLatestPolicy.Message,
    'invocation': SaveLatestPolicy.Invocation,
    'trigger': SaveLatestPolicy.Trigger,
}


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

@dataclass(kw_only=True)
class SessionManager:
    """Session persistence configuration attached to an agent."""
    session_id: str
    storage: StorageConfig
    save_latest: SaveLatestPolicy | None


class SnapshotScope(str):
    """Which kind of state a snapshot describes."""
    __slots__ = ()

    AGENT: SnapshotScope
    MULTI_AGENT: SnapshotScope

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


@dataclass(kw_only=True)
class SnapshotLocation:
    """Locator for a snapshot within the storage hierarchy."""
    session_id: str
    scope: SnapshotScope
    scope_id: str


@dataclass(kw_only=True)
class SlidingWindowState:
    """Sliding-window conversation manager state at snapshot time."""
    removed_message_count: int


@dataclass(kw_only=True)
class SummarizingState:
    """Summarizing conversation manager state at snapshot time."""
    summary_message: Message | None
    removed_message_count: int


class ConversationManagerState:
    """Conversation manager snapshot state. Wrapped in ``option<>`` at the
call site; ``none`` means there's no manager and nothing to persist."""
    if TYPE_CHECKING:
        SlidingWindow: ClassVar[type["_ConversationManagerState_SlidingWindow"]]
        Summarizing: ClassVar[type["_ConversationManagerState_Summarizing"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "ConversationManagerState": ...

class _ConversationManagerState_SlidingWindow(_WitVariantCase, ConversationManagerState):
    """Sliding-window manager state."""
    tag = 'sliding-window'
ConversationManagerState.SlidingWindow = _ConversationManagerState_SlidingWindow  # type: ignore[attr-defined]

class _ConversationManagerState_Summarizing(_WitVariantCase, ConversationManagerState):
    """Summarizing manager state."""
    tag = 'summarizing'
ConversationManagerState.Summarizing = _ConversationManagerState_Summarizing  # type: ignore[attr-defined]

ConversationManagerState._CASES = {  # type: ignore[attr-defined]
    'sliding-window': ConversationManagerState.SlidingWindow,
    'summarizing': ConversationManagerState.Summarizing,
}


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

@dataclass(kw_only=True)
class RetryStrategyState:
    """Retry-strategy state at snapshot time."""
    attempts_used: int
    elapsed_ms: int


@dataclass(kw_only=True)
class PluginStateEntry:
    """Named plugin state. `data` is an opaque JSON object owned by the plugin."""
    plugin_name: str
    data: str


@dataclass(kw_only=True)
class SnapshotData:
    """Framework-owned snapshot state. All fields are optional because an
agent may not exercise every subsystem in a given run."""
    messages: list[Message]
    conversation_manager: ConversationManagerState | None
    retry_strategy: RetryStrategyState | None
    model_state: str | None
    plugins: list[PluginStateEntry]


@dataclass(kw_only=True)
class Snapshot:
    """Point-in-time capture of agent or orchestrator state."""
    scope: SnapshotScope
    schema_version: str
    created_at: Datetime
    data: SnapshotData
    app_data: str


@dataclass(kw_only=True)
class SnapshotManifest:
    """Metadata describing the snapshot manifest file."""
    schema_version: str
    updated_at: Datetime


class StorageError:
    """Why a snapshot operation failed."""
    if TYPE_CHECKING:
        NotFound: ClassVar[type["_StorageError_NotFound"]]
        AccessDenied: ClassVar[type["_StorageError_AccessDenied"]]
        OutOfSpace: ClassVar[type["_StorageError_OutOfSpace"]]
        Corrupt: ClassVar[type["_StorageError_Corrupt"]]
        Conflict: ClassVar[type["_StorageError_Conflict"]]
        Transient: ClassVar[type["_StorageError_Transient"]]
        Permanent: ClassVar[type["_StorageError_Permanent"]]
        UnknownBackend: ClassVar[type["_StorageError_UnknownBackend"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "StorageError": ...

class _StorageError_NotFound(_WitVariantCase, StorageError):
    """No snapshot or manifest at the requested location."""
    tag = 'not-found'
StorageError.NotFound = _StorageError_NotFound  # type: ignore[attr-defined]

class _StorageError_AccessDenied(_WitVariantCase, StorageError):
    """Caller lacks permission to read or write the storage."""
    tag = 'access-denied'
StorageError.AccessDenied = _StorageError_AccessDenied  # type: ignore[attr-defined]

class _StorageError_OutOfSpace(_WitVariantCase, StorageError):
    """Backing storage is full or over quota."""
    tag = 'out-of-space'
StorageError.OutOfSpace = _StorageError_OutOfSpace  # type: ignore[attr-defined]

class _StorageError_Corrupt(_WitVariantCase, StorageError):
    """Snapshot is malformed or cannot be deserialized."""
    tag = 'corrupt'
StorageError.Corrupt = _StorageError_Corrupt  # type: ignore[attr-defined]

class _StorageError_Conflict(_WitVariantCase, StorageError):
    """Concurrent writers collided; retrying may succeed."""
    tag = 'conflict'
StorageError.Conflict = _StorageError_Conflict  # type: ignore[attr-defined]

class _StorageError_Transient(_WitVariantCase, StorageError):
    """Transient I/O failure; retrying may succeed."""
    tag = 'transient'
StorageError.Transient = _StorageError_Transient  # type: ignore[attr-defined]

class _StorageError_Permanent(_WitVariantCase, StorageError):
    """Permanent backend failure."""
    tag = 'permanent'
StorageError.Permanent = _StorageError_Permanent  # type: ignore[attr-defined]

class _StorageError_UnknownBackend(_WitVariantCase, StorageError):
    """No custom backend registered for the given backend-id."""
    tag = 'unknown-backend'
StorageError.UnknownBackend = _StorageError_UnknownBackend  # type: ignore[attr-defined]

StorageError._CASES = {  # type: ignore[attr-defined]
    'not-found': StorageError.NotFound,
    'access-denied': StorageError.AccessDenied,
    'out-of-space': StorageError.OutOfSpace,
    'corrupt': StorageError.Corrupt,
    'conflict': StorageError.Conflict,
    'transient': StorageError.Transient,
    'permanent': StorageError.Permanent,
    'unknown-backend': StorageError.UnknownBackend,
}


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