# Code generated by ndpgen. DO NOT EDIT.
#
# This file contains client wrappers for the Comprehensive host service.
# It is intended for use in Navidrome plugins built with extism-py.
#
# IMPORTANT: Due to a limitation in extism-py, you cannot import this file directly.
# The @extism.import_fn decorators are only detected when defined in the plugin's
# main __init__.py file. Copy the needed functions from this file into your plugin.

from dataclasses import dataclass
from typing import Any

import extism
import json
import base64


class HostFunctionError(Exception):
    """Raised when a host function returns an error."""
    pass


@extism.import_fn("extism:host/user", "comprehensive_simpleparams")
def _comprehensive_simpleparams(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_structparam")
def _comprehensive_structparam(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_mixedparams")
def _comprehensive_mixedparams(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_noerror")
def _comprehensive_noerror(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_noparams")
def _comprehensive_noparams(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_noparamsnoreturns")
def _comprehensive_noparamsnoreturns(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_pointerparams")
def _comprehensive_pointerparams(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_mapparams")
def _comprehensive_mapparams(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_multiplereturns")
def _comprehensive_multiplereturns(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@extism.import_fn("extism:host/user", "comprehensive_byteslice")
def _comprehensive_byteslice(offset: int) -> int:
    """Raw host function - do not call directly."""
    ...


@dataclass
class ComprehensiveMultipleReturnsResult:
    """Result type for comprehensive_multiple_returns."""
    results: Any
    total: int


def comprehensive_simple_params(name: str, count: int) -> str:
    """Call the comprehensive_simpleparams host function.

    Args:
        name: str parameter.
        count: int parameter.

    Returns:
        str: The result value.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request = {
        "name": name,
        "count": count,
    }
    request_bytes = json.dumps(request).encode("utf-8")
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_simpleparams(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])

    return response.get("result", "")


def comprehensive_struct_param(user: Any) -> None:
    """Call the comprehensive_structparam host function.

    Args:
        user: Any parameter.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request = {
        "user": user,
    }
    request_bytes = json.dumps(request).encode("utf-8")
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_structparam(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])



def comprehensive_mixed_params(id: str, filter: Any) -> int:
    """Call the comprehensive_mixedparams host function.

    Args:
        id: str parameter.
        filter: Any parameter.

    Returns:
        int: The result value.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request = {
        "id": id,
        "filter": filter,
    }
    request_bytes = json.dumps(request).encode("utf-8")
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_mixedparams(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])

    return response.get("result", 0)


def comprehensive_no_error(name: str) -> str:
    """Call the comprehensive_noerror host function.

    Args:
        name: str parameter.

    Returns:
        str: The result value.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request = {
        "name": name,
    }
    request_bytes = json.dumps(request).encode("utf-8")
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_noerror(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])

    return response.get("result", "")


def comprehensive_no_params() -> None:
    """Call the comprehensive_noparams host function.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request_bytes = b"{}"
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_noparams(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])



def comprehensive_no_params_no_returns() -> None:
    """Call the comprehensive_noparamsnoreturns host function.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request_bytes = b"{}"
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_noparamsnoreturns(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])



def comprehensive_pointer_params(id: Any, user: Any) -> Any:
    """Call the comprehensive_pointerparams host function.

    Args:
        id: Any parameter.
        user: Any parameter.

    Returns:
        Any: The result value.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request = {
        "id": id,
        "user": user,
    }
    request_bytes = json.dumps(request).encode("utf-8")
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_pointerparams(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])

    return response.get("result", None)


def comprehensive_map_params(data: Any) -> Any:
    """Call the comprehensive_mapparams host function.

    Args:
        data: Any parameter.

    Returns:
        Any: The result value.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request = {
        "data": data,
    }
    request_bytes = json.dumps(request).encode("utf-8")
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_mapparams(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])

    return response.get("result", None)


def comprehensive_multiple_returns(query: str) -> ComprehensiveMultipleReturnsResult:
    """Call the comprehensive_multiplereturns host function.

    Args:
        query: str parameter.

    Returns:
        ComprehensiveMultipleReturnsResult containing results, total,.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request = {
        "query": query,
    }
    request_bytes = json.dumps(request).encode("utf-8")
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_multiplereturns(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])

    return ComprehensiveMultipleReturnsResult(
        results=response.get("results", None),
        total=response.get("total", 0),
    )


def comprehensive_byte_slice(data: bytes) -> bytes:
    """Call the comprehensive_byteslice host function.

    Args:
        data: bytes parameter.

    Returns:
        bytes: The result value.

    Raises:
        HostFunctionError: If the host function returns an error.
    """
    request = {
        "data": base64.b64encode(data).decode("ascii"),
    }
    request_bytes = json.dumps(request).encode("utf-8")
    request_mem = extism.memory.alloc(request_bytes)
    response_offset = _comprehensive_byteslice(request_mem.offset)
    response_mem = extism.memory.find(response_offset)
    response = json.loads(extism.memory.string(response_mem))

    if response.get("error"):
        raise HostFunctionError(response["error"])

    return base64.b64decode(response.get("result", ""))
