"""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 .error import Error
from .poll import Pollable


StreamError = Any | None
"""An error for input-stream and output-stream operations."""

class InputStream:
    """An input bytestream.

`input-stream`s are *non-blocking* to the extent practical on underlying
platforms. I/O operations always return promptly; if fewer bytes are
promptly available than requested, they return the number of bytes promptly
available, which could even be zero. To wait for data to be available,
use the `subscribe` function to obtain a `pollable` which can be polled
for using `wasi:io/poll`."""
    # 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, len: int) -> Any:
        return self._invoke('[method]input-stream.read', (self._handle, len,))

    def blocking_read(self, len: int) -> Any:
        return self._invoke('[method]input-stream.blocking-read', (self._handle, len,))

    def skip(self, len: int) -> Any:
        return self._invoke('[method]input-stream.skip', (self._handle, len,))

    def blocking_skip(self, len: int) -> Any:
        return self._invoke('[method]input-stream.blocking-skip', (self._handle, len,))

    def subscribe(self) -> Any:
        return self._invoke('[method]input-stream.subscribe', (self._handle,))


class OutputStream:
    """An output bytestream.

`output-stream`s are *non-blocking* to the extent practical on
underlying platforms. Except where specified otherwise, I/O operations also
always return promptly, after the number of bytes that can be written
promptly, which could even be zero. To wait for the stream to be ready to
accept data, the `subscribe` function to obtain a `pollable` which can be
polled for using `wasi:io/poll`.

Dropping an `output-stream` while there's still an active write in
progress may result in the data being lost. Before dropping the stream,
be sure to fully flush your writes."""
    # 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 check_write(self) -> Any:
        return self._invoke('[method]output-stream.check-write', (self._handle,))

    def write(self, contents: bytes) -> Any:
        return self._invoke('[method]output-stream.write', (self._handle, contents,))

    def blocking_write_and_flush(self, contents: bytes) -> Any:
        return self._invoke('[method]output-stream.blocking-write-and-flush', (self._handle, contents,))

    def flush(self) -> Any:
        return self._invoke('[method]output-stream.flush', (self._handle,))

    def blocking_flush(self) -> Any:
        return self._invoke('[method]output-stream.blocking-flush', (self._handle,))

    def subscribe(self) -> Any:
        return self._invoke('[method]output-stream.subscribe', (self._handle,))

    def write_zeroes(self, len: int) -> Any:
        return self._invoke('[method]output-stream.write-zeroes', (self._handle, len,))

    def blocking_write_zeroes_and_flush(self, len: int) -> Any:
        return self._invoke('[method]output-stream.blocking-write-zeroes-and-flush', (self._handle, len,))

    def splice(self, src: Any, len: int) -> Any:
        return self._invoke('[method]output-stream.splice', (self._handle, src, len,))

    def blocking_splice(self, src: Any, len: int) -> Any:
        return self._invoke('[method]output-stream.blocking-splice', (self._handle, src, len,))
