"""Auto-generated Moonraker API bindings — DO NOT EDIT.

Generated by ``scripts/generate_bindings.py`` from ``schema/moonraker_api.yaml``.
"""

from __future__ import annotations

import builtins  # noqa: TC003
from typing import TYPE_CHECKING, Any, cast

from pymoonraker.models.access import (
    AccessLoginResponse,
    AccessLogoutResponse,
    AccessRefreshJwtResponse,
    AccessUserInfo,
    AccessUsersListResponse,
)
from pymoonraker.models.announcements import AnnouncementDismissResponse, AnnouncementsListResponse
from pymoonraker.models.common import PrinterObjectList
from pymoonraker.models.database import DatabaseItemResponse, DatabaseListResponse
from pymoonraker.models.devices import PowerDevicesResponse
from pymoonraker.models.files import (
    FileActionResponse,
    FileItem,
    FileMetadata,
    FileMoveResponse,
    FileRoot,
)
from pymoonraker.models.job import (
    HistoryDeleteResponse,
    HistoryJobResponse,
    HistoryListResponse,
    HistoryTotals,
    JobQueueStatus,
)
from pymoonraker.models.machine import MachineProcStatsResponse, MachineSystemInfoResponse
from pymoonraker.models.printer import PrinterObjectsStatusResponse
from pymoonraker.models.server import (
    ConnectionIdentifyResult,
    GcodeStoreResponse,
    PrinterInfo,
    ServerConfigResponse,
    ServerInfo,
    TemperatureStoreResponse,
)
from pymoonraker.models.update_manager import UpdateManagerStatusResponse
from pymoonraker.models.webcams import WebcamGetResponse, WebcamsListResponse

if TYPE_CHECKING:
    from pymoonraker.client import MoonrakerClient


class PrinterNamespace:
    """Klipper printer administration.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def info(self) -> PrinterInfo:
        """Get Klipper host information (state, hostname, versions)."""
        raw = await self._client.call("printer.info")
        return PrinterInfo.model_validate(raw)

    async def emergency_stop(self) -> str:
        """Immediately halt the printer."""
        raw = await self._client.call("printer.emergency_stop")
        return cast("str", raw)

    async def restart(self) -> str:
        """Soft-restart Klipper host software."""
        raw = await self._client.call("printer.restart")
        return cast("str", raw)

    async def firmware_restart(self) -> str:
        """Restart Klipper via firmware restart (MCU reset)."""
        raw = await self._client.call("printer.firmware_restart")
        return cast("str", raw)

    async def gcode_script(self, script: str) -> str:
        """Execute a G-code script.

        Args:
            script: G-code to execute

        """
        params: dict[str, Any] = {}
        params["script"] = script
        raw = await self._client.call("printer.gcode.script", params)
        return cast("str", raw)

    async def gcode_help(self) -> builtins.dict[str, str]:
        """List all available G-code commands with descriptions."""
        raw = await self._client.call("printer.gcode.help")
        return cast("builtins.dict[str, str]", raw)

    async def objects_list(self) -> PrinterObjectList:
        """List all available printer objects."""
        raw = await self._client.call("printer.objects.list")
        return PrinterObjectList.model_validate(raw)

    async def objects_query(
        self,
        objects: builtins.dict[str, builtins.list[str] | None],
    ) -> PrinterObjectsStatusResponse:
        """Query printer object status.

        Args:
            objects: Mapping of object name to list of fields (or None for all fields)

        """
        params: dict[str, Any] = {}
        params["objects"] = objects
        raw = await self._client.call("printer.objects.query", params)
        return PrinterObjectsStatusResponse.model_validate(raw)

    async def objects_subscribe(
        self,
        objects: builtins.dict[str, builtins.list[str] | None],
    ) -> PrinterObjectsStatusResponse:
        """Subscribe to printer object status updates.

        Args:
            objects: Objects and fields to subscribe to

        """
        params: dict[str, Any] = {}
        params["objects"] = objects
        raw = await self._client.call("printer.objects.subscribe", params)
        return PrinterObjectsStatusResponse.model_validate(raw)

    async def print_start(self, filename: str) -> str:
        """Start printing a file.

        Args:
            filename: Path to the G-code file to print

        """
        params: dict[str, Any] = {}
        params["filename"] = filename
        raw = await self._client.call("printer.print.start", params)
        return cast("str", raw)

    async def print_pause(self) -> str:
        """Pause the current print."""
        raw = await self._client.call("printer.print.pause")
        return cast("str", raw)

    async def print_resume(self) -> str:
        """Resume a paused print."""
        raw = await self._client.call("printer.print.resume")
        return cast("str", raw)

    async def print_cancel(self) -> str:
        """Cancel the current print."""
        raw = await self._client.call("printer.print.cancel")
        return cast("str", raw)


class ServerNamespace:
    """Moonraker server administration.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def info(self) -> ServerInfo:
        """Get Moonraker server information."""
        raw = await self._client.call("server.info")
        return ServerInfo.model_validate(raw)

    async def config(self) -> ServerConfigResponse:
        """Get the full Moonraker configuration."""
        raw = await self._client.call("server.config")
        return ServerConfigResponse.model_validate(raw)

    async def temperature_store(
        self,
        include_monitors: bool | None = None,
    ) -> TemperatureStoreResponse:
        """Get cached temperature history.

        Args:
            include_monitors: Include temperature monitors in the response

        """
        params: dict[str, Any] = {}
        if include_monitors is not None:
            params["include_monitors"] = include_monitors
        raw = await self._client.call("server.temperature_store", params)
        return TemperatureStoreResponse.model_validate(raw)

    async def gcode_store(self, count: int | None = None) -> GcodeStoreResponse:
        """Get cached G-code console responses.

        Args:
            count: Number of responses to return

        """
        params: dict[str, Any] = {}
        if count is not None:
            params["count"] = count
        raw = await self._client.call("server.gcode_store", params)
        return GcodeStoreResponse.model_validate(raw)

    async def restart(self) -> str:
        """Restart the Moonraker server."""
        raw = await self._client.call("server.restart")
        return cast("str", raw)

    async def connection_identify(
        self,
        client_name: str,
        version: str,
        type: str,
        url: str,
    ) -> ConnectionIdentifyResult:
        """Identify this client connection to the server.

        Args:
            client_name: Name of the client application
            version: Client version string
            type: Client type: web, desktop, mobile, agent, other
            url: Client homepage or repository URL

        """
        params: dict[str, Any] = {}
        params["client_name"] = client_name
        params["version"] = version
        params["type"] = type
        params["url"] = url
        raw = await self._client.call("server.connection.identify", params)
        return ConnectionIdentifyResult.model_validate(raw)


class FilesNamespace:
    """File and directory management.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def list(self, root: str | None = None) -> builtins.list[FileItem]:
        """List files in a root directory.

        Args:
            root: Root directory (default: gcodes)

        """
        params: dict[str, Any] = {}
        if root is not None:
            params["root"] = root
        raw = await self._client.call("server.files.list", params)
        return [FileItem.model_validate(item) for item in raw]

    async def roots(self) -> builtins.list[FileRoot]:
        """List all registered file root directories."""
        raw = await self._client.call("server.files.roots")
        return [FileRoot.model_validate(item) for item in raw]

    async def metadata(self, filename: str) -> FileMetadata:
        """Get detailed metadata for a G-code file.

        Args:
            filename: Path to the file relative to its root

        """
        params: dict[str, Any] = {}
        params["filename"] = filename
        raw = await self._client.call("server.files.metadata", params)
        return FileMetadata.model_validate(raw)

    async def create_directory(self, path: str) -> FileActionResponse:
        """Create a new directory.

        Args:
            path: Directory path to create

        """
        params: dict[str, Any] = {}
        params["path"] = path
        raw = await self._client.call("server.files.directory", params)
        return FileActionResponse.model_validate(raw)

    async def delete_directory(self, path: str, force: bool | None = None) -> FileActionResponse:
        """Delete a directory.

        Args:
            path: Directory path to delete
            force: Force delete non-empty directory

        """
        params: dict[str, Any] = {}
        params["path"] = path
        if force is not None:
            params["force"] = force
        raw = await self._client.call("server.files.delete_directory", params)
        return FileActionResponse.model_validate(raw)

    async def move(self, source: str, dest: str) -> FileMoveResponse:
        """Move or rename a file or directory.

        Args:
            source: Source path
            dest: Destination path

        """
        params: dict[str, Any] = {}
        params["source"] = source
        params["dest"] = dest
        raw = await self._client.call("server.files.move", params)
        return FileMoveResponse.model_validate(raw)

    async def copy(self, source: str, dest: str) -> FileActionResponse:
        """Copy a file or directory.

        Args:
            source: Source path
            dest: Destination path

        """
        params: dict[str, Any] = {}
        params["source"] = source
        params["dest"] = dest
        raw = await self._client.call("server.files.copy", params)
        return FileActionResponse.model_validate(raw)

    async def delete_file(self, root: str, path: str) -> FileActionResponse:
        """Delete a file.

        Args:
            root: File root
            path: File path relative to root

        """
        params: dict[str, Any] = {}
        params["root"] = root
        params["path"] = path
        raw = await self._client.call("server.files.delete_file", params)
        return FileActionResponse.model_validate(raw)


class JobQueueNamespace:
    """Print job queue management.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def status(self) -> JobQueueStatus:
        """Get job queue status and queued jobs."""
        raw = await self._client.call("server.job_queue.status")
        return JobQueueStatus.model_validate(raw)

    async def enqueue(self, filenames: builtins.list[str]) -> JobQueueStatus:
        """Add one or more jobs to the queue.

        Args:
            filenames: List of filenames to enqueue

        """
        params: dict[str, Any] = {}
        params["filenames"] = filenames
        raw = await self._client.call("server.job_queue.post_job", params)
        return JobQueueStatus.model_validate(raw)

    async def delete(self, job_ids: builtins.list[str]) -> JobQueueStatus:
        """Remove jobs from the queue.

        Args:
            job_ids: List of job IDs to remove

        """
        params: dict[str, Any] = {}
        params["job_ids"] = job_ids
        raw = await self._client.call("server.job_queue.delete_job", params)
        return JobQueueStatus.model_validate(raw)

    async def pause(self) -> JobQueueStatus:
        """Pause the job queue."""
        raw = await self._client.call("server.job_queue.pause")
        return JobQueueStatus.model_validate(raw)

    async def start(self) -> JobQueueStatus:
        """Start or resume the job queue."""
        raw = await self._client.call("server.job_queue.start")
        return JobQueueStatus.model_validate(raw)


class HistoryNamespace:
    """Print history.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def list(
        self,
        limit: int | None = None,
        start: int | None = None,
        since: float | None = None,
        before: float | None = None,
        order: str | None = None,
    ) -> HistoryListResponse:
        """List job history entries.

        Args:
            limit: Maximum number of entries to return
            start: Starting index
            since: Unix timestamp; only return jobs after this time
            before: Unix timestamp; only return jobs before this time
            order: Sort order: asc or desc

        """
        params: dict[str, Any] = {}
        if limit is not None:
            params["limit"] = limit
        if start is not None:
            params["start"] = start
        if since is not None:
            params["since"] = since
        if before is not None:
            params["before"] = before
        if order is not None:
            params["order"] = order
        raw = await self._client.call("server.history.list", params)
        return HistoryListResponse.model_validate(raw)

    async def totals(self) -> HistoryTotals:
        """Get aggregate print statistics."""
        raw = await self._client.call("server.history.totals")
        return HistoryTotals.model_validate(raw)

    async def get_job(self, uid: str) -> HistoryJobResponse:
        """Get details of a single history job.

        Args:
            uid: Job ID

        """
        params: dict[str, Any] = {}
        params["uid"] = uid
        raw = await self._client.call("server.history.get_job", params)
        return HistoryJobResponse.model_validate(raw)

    async def delete_job(self, uid: str) -> HistoryDeleteResponse:
        """Delete a history entry.

        Args:
            uid: Job ID to delete

        """
        params: dict[str, Any] = {}
        params["uid"] = uid
        raw = await self._client.call("server.history.delete_job", params)
        return HistoryDeleteResponse.model_validate(raw)


class MachineNamespace:
    """Host machine administration.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def system_info(self) -> MachineSystemInfoResponse:
        """Get host system information (CPU, distro, network)."""
        raw = await self._client.call("machine.system_info")
        return MachineSystemInfoResponse.model_validate(raw)

    async def shutdown(self) -> str:
        """Shut down the host machine."""
        raw = await self._client.call("machine.shutdown")
        return cast("str", raw)

    async def reboot(self) -> str:
        """Reboot the host machine."""
        raw = await self._client.call("machine.reboot")
        return cast("str", raw)

    async def proc_stats(self) -> MachineProcStatsResponse:
        """Get process statistics for Moonraker and system."""
        raw = await self._client.call("machine.proc_stats")
        return MachineProcStatsResponse.model_validate(raw)

    async def restart_service(self, service: str) -> str:
        """Restart a systemd service.

        Args:
            service: Service name to restart

        """
        params: dict[str, Any] = {}
        params["service"] = service
        raw = await self._client.call("machine.services.restart", params)
        return cast("str", raw)

    async def stop_service(self, service: str) -> str:
        """Stop a systemd service.

        Args:
            service: Service name to stop

        """
        params: dict[str, Any] = {}
        params["service"] = service
        raw = await self._client.call("machine.services.stop", params)
        return cast("str", raw)

    async def start_service(self, service: str) -> str:
        """Start a systemd service.

        Args:
            service: Service name to start

        """
        params: dict[str, Any] = {}
        params["service"] = service
        raw = await self._client.call("machine.services.start", params)
        return cast("str", raw)


class UpdateManagerNamespace:
    """Software update management.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def status(self, refresh: bool | None = None) -> UpdateManagerStatusResponse:
        """Get update status for all tracked software.

        Args:
            refresh: Refresh update state from remote

        """
        params: dict[str, Any] = {}
        if refresh is not None:
            params["refresh"] = refresh
        raw = await self._client.call("machine.update.status", params)
        return UpdateManagerStatusResponse.model_validate(raw)

    async def refresh(self) -> UpdateManagerStatusResponse:
        """Force refresh of update state from remote."""
        raw = await self._client.call("machine.update.refresh")
        return UpdateManagerStatusResponse.model_validate(raw)


class PowerNamespace:
    """Power device control.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def devices(self) -> PowerDevicesResponse:
        """List all configured power devices."""
        raw = await self._client.call("machine.device_power.devices")
        return PowerDevicesResponse.model_validate(raw)

    async def get_device(self, device: str) -> builtins.dict[str, str]:
        """Get power state of a device.

        Args:
            device: Device name

        """
        params: dict[str, Any] = {}
        params["device"] = device
        raw = await self._client.call("machine.device_power.get_device", params)
        return cast("builtins.dict[str, str]", raw)

    async def set_device(self, device: str, action: str) -> builtins.dict[str, str]:
        """Set power state of a device.

        Args:
            device: Device name
            action: Action: on, off, or toggle

        """
        params: dict[str, Any] = {}
        params["device"] = device
        params["action"] = action
        raw = await self._client.call("machine.device_power.post_device", params)
        return cast("builtins.dict[str, str]", raw)


class AccessNamespace:
    """User authentication and API key management.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def login(self, username: str, password: str) -> AccessLoginResponse:
        """Authenticate with username and password.

        Args:
            username: Username
            password: Password

        """
        params: dict[str, Any] = {}
        params["username"] = username
        params["password"] = password
        raw = await self._client.call("access.login", params)
        return AccessLoginResponse.model_validate(raw)

    async def logout(self) -> AccessLogoutResponse:
        """Invalidate current session."""
        raw = await self._client.call("access.logout")
        return AccessLogoutResponse.model_validate(raw)

    async def get_user(self) -> AccessUserInfo:
        """Get current authenticated user info."""
        raw = await self._client.call("access.get_user")
        return AccessUserInfo.model_validate(raw)

    async def list_users(self) -> AccessUsersListResponse:
        """List all registered users."""
        raw = await self._client.call("access.users.list")
        return AccessUsersListResponse.model_validate(raw)

    async def refresh_jwt(self, refresh_token: str) -> AccessRefreshJwtResponse:
        """Refresh an expired JWT access token.

        Args:
            refresh_token: Refresh token from login

        """
        params: dict[str, Any] = {}
        params["refresh_token"] = refresh_token
        raw = await self._client.call("access.refresh_jwt", params)
        return AccessRefreshJwtResponse.model_validate(raw)

    async def get_api_key(self) -> str:
        """Get the current API key."""
        raw = await self._client.call("access.api_key")
        return cast("str", raw)

    async def oneshot_token(self) -> str:
        """Generate a single-use authentication token."""
        raw = await self._client.call("access.oneshot_token")
        return cast("str", raw)


class DatabaseNamespace:
    """Moonraker key-value database.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def list_namespaces(self) -> DatabaseListResponse:
        """List all database namespaces."""
        raw = await self._client.call("server.database.list")
        return DatabaseListResponse.model_validate(raw)

    async def get_item(self, namespace: str, key: str | None = None) -> DatabaseItemResponse:
        """Retrieve a value from the database.

        Args:
            namespace: Database namespace
            key: Key to retrieve (omit for full namespace)

        """
        params: dict[str, Any] = {}
        params["namespace"] = namespace
        if key is not None:
            params["key"] = key
        raw = await self._client.call("server.database.get_item", params)
        return DatabaseItemResponse.model_validate(raw)

    async def post_item(self, namespace: str, key: str, value: Any) -> DatabaseItemResponse:
        """Store or update a value in the database.

        Args:
            namespace: Database namespace
            key: Key to set
            value: Value to store

        """
        params: dict[str, Any] = {}
        params["namespace"] = namespace
        params["key"] = key
        params["value"] = value
        raw = await self._client.call("server.database.post_item", params)
        return DatabaseItemResponse.model_validate(raw)

    async def delete_item(self, namespace: str, key: str) -> DatabaseItemResponse:
        """Delete a value from the database.

        Args:
            namespace: Database namespace
            key: Key to delete

        """
        params: dict[str, Any] = {}
        params["namespace"] = namespace
        params["key"] = key
        raw = await self._client.call("server.database.delete_item", params)
        return DatabaseItemResponse.model_validate(raw)


class AnnouncementsNamespace:
    """Moonraker announcement system.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def list(self, include_dismissed: bool | None = None) -> AnnouncementsListResponse:
        """List current announcements.

        Args:
            include_dismissed: Include dismissed announcements

        """
        params: dict[str, Any] = {}
        if include_dismissed is not None:
            params["include_dismissed"] = include_dismissed
        raw = await self._client.call("server.announcements.list", params)
        return AnnouncementsListResponse.model_validate(raw)

    async def dismiss(self, entry_id: str) -> AnnouncementDismissResponse:
        """Dismiss an announcement.

        Args:
            entry_id: Announcement entry ID

        """
        params: dict[str, Any] = {}
        params["entry_id"] = entry_id
        raw = await self._client.call("server.announcements.dismiss", params)
        return AnnouncementDismissResponse.model_validate(raw)


class WebcamsNamespace:
    """Webcam configuration.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def list(self) -> WebcamsListResponse:
        """List configured webcams."""
        raw = await self._client.call("server.webcams.list")
        return WebcamsListResponse.model_validate(raw)

    async def get(self, name: str) -> WebcamGetResponse:
        """Get a single webcam configuration.

        Args:
            name: Webcam name

        """
        params: dict[str, Any] = {}
        params["name"] = name
        raw = await self._client.call("server.webcams.get_item", params)
        return WebcamGetResponse.model_validate(raw)
