// Code generated by ndpgen. DO NOT EDIT.
//
// This file contains client wrappers for the Echo host service.
// It is intended for use in Navidrome plugins built with extism-pdk.

use extism_pdk::*;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct EchoEchoRequest {
    message: String,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
struct EchoEchoResponse {
    #[serde(default)]
    reply: String,
    #[serde(default)]
    error: Option<String>,
}

#[host_fn]
extern "ExtismHost" {
    fn echo_echo(input: Json<EchoEchoRequest>) -> Json<EchoEchoResponse>;
}

/// Calls the echo_echo host function.
///
/// # Arguments
/// * `message` - String parameter.
///
/// # Returns
/// The reply value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn echo(message: &str) -> Result<String, Error> {
    let response = unsafe {
        echo_echo(Json(EchoEchoRequest {
            message: message.to_owned(),
        }))?
    };

    if let Some(err) = response.0.error {
        return Err(Error::msg(err));
    }

    Ok(response.0.reply)
}
