"""Type stubs for _rapfiles Rust extension module."""

from typing import Coroutine, Any, Optional, Union, List, Tuple, Type

# File operations
def read_file_async(path: str) -> Coroutine[Any, Any, str]: ...
def write_file_async(path: str, contents: str) -> Coroutine[Any, Any, None]: ...
def read_file_bytes_async(path: str) -> Coroutine[Any, Any, bytes]: ...
def write_file_bytes_async(path: str, contents: bytes) -> Coroutine[Any, Any, None]: ...
def append_file_async(path: str, contents: str) -> Coroutine[Any, Any, None]: ...

# File handles
def open_file(
    path: str,
    mode: str = "r",
    buffering: int = -1,
    encoding: Optional[str] = None,
    errors: Optional[str] = None,
    newline: Optional[str] = None,
    closefd: bool = True,
    opener: Optional[Any] = None,
) -> Coroutine[Any, Any, "AsyncFile"]: ...

# Directory operations
def create_dir_async(path: str) -> Coroutine[Any, Any, None]: ...
def create_dir_all_async(path: str) -> Coroutine[Any, Any, None]: ...
def remove_dir_async(path: str) -> Coroutine[Any, Any, None]: ...
def remove_dir_all_async(path: str) -> Coroutine[Any, Any, None]: ...
def list_dir_async(path: str) -> Coroutine[Any, Any, List[str]]: ...
def exists_async(path: str) -> Coroutine[Any, Any, bool]: ...
def is_file_async(path: str) -> Coroutine[Any, Any, bool]: ...
def is_dir_async(path: str) -> Coroutine[Any, Any, bool]: ...

# Metadata operations
def stat_async(path: str) -> Coroutine[Any, Any, "FileMetadata"]: ...
def metadata_async(path: str) -> Coroutine[Any, Any, "FileMetadata"]: ...

# Directory traversal
def walk_dir_async(path: str) -> Coroutine[Any, Any, List[Tuple[str, bool]]]: ...

class AsyncFile:
    """Async file handle for true async I/O operations."""

    def __init__(
        self,
        path: str,
        mode: str = "r",
        buffering: int = -1,
        encoding: Optional[str] = None,
        errors: Optional[str] = None,
        newline: Optional[str] = None,
        closefd: bool = True,
        opener: Optional[Any] = None,
    ) -> None: ...
    def read(self, size: int = -1) -> Coroutine[Any, Any, bytes]: ...
    def write(self, data: Union[str, bytes]) -> Coroutine[Any, Any, int]: ...
    def readline(self, size: int = -1) -> Coroutine[Any, Any, bytes]: ...
    def readlines(self, hint: int = -1) -> Coroutine[Any, Any, List[bytes]]: ...
    def seek(self, offset: int, whence: int = 0) -> Coroutine[Any, Any, int]: ...
    def tell(self) -> Coroutine[Any, Any, int]: ...
    def close(self) -> Coroutine[Any, Any, None]: ...
    def __aenter__(self) -> "AsyncFile": ...
    def __aexit__(
        self,
        exc_type: Optional[Type[BaseException]],
        exc_val: Optional[BaseException],
        exc_tb: Optional[Any],
    ) -> Coroutine[Any, Any, bool]: ...

class FileMetadata:
    """File metadata structure (aiofiles.stat_result compatible)."""

    def __init__(
        self,
        size: int,
        is_file: bool,
        is_dir: bool,
        modified: float,
        accessed: float,
        created: float,
    ) -> None: ...
    @property
    def size(self) -> int: ...
    @property
    def is_file(self) -> bool: ...
    @property
    def is_dir(self) -> bool: ...
    @property
    def modified(self) -> float: ...
    @property
    def accessed(self) -> float: ...
    @property
    def created(self) -> float: ...
