from . import SFTPConfigEntry as SFTPConfigEntry, SFTPConfigEntryData as SFTPConfigEntryData
from .const import BUF_SIZE as BUF_SIZE, LOGGER as LOGGER
from _typeshed import Incomplete
from asyncssh import SFTPClient as SFTPClient, SFTPClientFile as SFTPClientFile, SSHClientConnection as SSHClientConnection, SSHClientConnectionOptions
from collections.abc import AsyncIterator
from dataclasses import dataclass
from homeassistant.components.backup import AgentBackup as AgentBackup, BackupAgentError as BackupAgentError, suggested_filename as suggested_filename
from homeassistant.core import HomeAssistant as HomeAssistant
from types import TracebackType
from typing import Self

def get_client_options(cfg: SFTPConfigEntryData) -> SSHClientConnectionOptions: ...

class AsyncFileIterator:
    _client: BackupAgentClient
    _fileobj: SFTPClientFile
    cfg: SFTPConfigEntry
    hass: HomeAssistant
    file_path: str
    buffer_size: Incomplete
    _initialized: bool
    def __init__(self, cfg: SFTPConfigEntry, hass: HomeAssistant, file_path: str, buffer_size: int = ...) -> None: ...
    async def _initialize(self) -> None: ...
    def __aiter__(self) -> AsyncIterator[bytes]: ...
    async def __anext__(self) -> bytes: ...

@dataclass(kw_only=True)
class BackupMetadata:
    file_path: str
    metadata: dict[str, str | dict[str, list[str]]]
    metadata_file: str

class BackupAgentClient:
    sftp: SFTPClient
    cfg: SFTPConfigEntry
    hass: HomeAssistant
    _ssh: SSHClientConnection | None
    def __init__(self, config: SFTPConfigEntry, hass: HomeAssistant) -> None: ...
    async def __aenter__(self) -> Self: ...
    async def __aexit__(self, exc_type: type[BaseException] | None, exc: BaseException | None, traceback: TracebackType | None) -> None: ...
    async def _load_metadata(self, backup_id: str) -> BackupMetadata: ...
    async def async_delete_backup(self, backup_id: str) -> None: ...
    async def async_list_backups(self) -> list[AgentBackup]: ...
    async def async_upload_backup(self, iterator: AsyncIterator[bytes], backup: AgentBackup) -> None: ...
    async def close(self) -> None: ...
    async def iter_file(self, backup_id: str) -> AsyncFileIterator: ...
    async def list_backup_location(self) -> list[str]: ...
    async def open(self) -> BackupAgentClient: ...
