// Code generated by ndpgen. DO NOT EDIT.
//
// This file contains client wrappers for the Math 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 MathAddRequest {
    a: i32,
    b: i32,
}

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

#[host_fn]
extern "ExtismHost" {
    fn math_add(input: Json<MathAddRequest>) -> Json<MathAddResponse>;
}

/// Calls the math_add host function.
///
/// # Arguments
/// * `a` - i32 parameter.
/// * `b` - i32 parameter.
///
/// # Returns
/// The result value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn add(a: i32, b: i32) -> Result<i32, Error> {
    let response = unsafe {
        math_add(Json(MathAddRequest {
            a: a,
            b: b,
        }))?
    };

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

    Ok(response.0.result)
}
