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

    class File(_WitVariantCase):
        """Local filesystem."""
        tag = 'file'

    class S3(_WitVariantCase):
        """Amazon S3."""
        tag = 's3'

    class Custom(_WitVariantCase):
        """Application-implemented backend."""
        tag = 'custom'

    _CASES: dict[str, type] = {
        'file': File,
        's3': S3,
        'custom': Custom,
    }

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

class SaveLatestPolicy:
    """When to update the "latest" snapshot pointer. The `trigger` arm
carries the id of an application-supplied callback that decides
per-invocation."""

    class Message(_WitVariantCase):
        """After every message added to the conversation."""
        tag = 'message'

    class Invocation(_WitVariantCase):
        """Once per invocation, after it completes."""
        tag = 'invocation'

    class Trigger(_WitVariantCase):
        """Each invocation consults the named `snapshot-trigger-handler`.
The id identifies which handler to invoke."""
        tag = 'trigger'

    _CASES: dict[str, type] = {
        'message': Message,
        'invocation': Invocation,
        'trigger': Trigger,
    }

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

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

    class SlidingWindow(_WitVariantCase):
        """Sliding-window manager state."""
        tag = 'sliding-window'

    class Summarizing(_WitVariantCase):
        """Summarizing manager state."""
        tag = 'summarizing'

    _CASES: dict[str, type] = {
        'sliding-window': SlidingWindow,
        'summarizing': Summarizing,
    }

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

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

    class NotFound(_WitVariantCase):
        """No snapshot or manifest at the requested location."""
        tag = 'not-found'

    class AccessDenied(_WitVariantCase):
        """Caller lacks permission to read or write the storage."""
        tag = 'access-denied'

    class OutOfSpace(_WitVariantCase):
        """Backing storage is full or over quota."""
        tag = 'out-of-space'

    class Corrupt(_WitVariantCase):
        """Snapshot is malformed or cannot be deserialized."""
        tag = 'corrupt'

    class Conflict(_WitVariantCase):
        """Concurrent writers collided; retrying may succeed."""
        tag = 'conflict'

    class Transient(_WitVariantCase):
        """Transient I/O failure; retrying may succeed."""
        tag = 'transient'

    class Permanent(_WitVariantCase):
        """Permanent backend failure."""
        tag = 'permanent'

    class UnknownBackend(_WitVariantCase):
        """No custom backend registered for the given backend-id."""
        tag = 'unknown-backend'

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

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