// Code generated by ndpgen. DO NOT EDIT.
//
// This file contains client wrappers for the Users 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, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct User {
    pub id: String,
    pub name: String,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct UsersGetRequest {
    id: Option<String>,
    filter: Option<User>,
}

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

#[host_fn]
extern "ExtismHost" {
    fn users_get(input: Json<UsersGetRequest>) -> Json<UsersGetResponse>;
}

/// Calls the users_get host function.
///
/// # Arguments
/// * `id` - Option<String> parameter.
/// * `filter` - Option<User> parameter.
///
/// # Returns
/// The result value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get(id: Option<String>, filter: Option<User>) -> Result<Option<User>, Error> {
    let response = unsafe {
        users_get(Json(UsersGetRequest {
            id: id,
            filter: filter,
        }))?
    };

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

    Ok(response.0.result)
}
