// Code generated by ndpgen. DO NOT EDIT.
//
// This file contains client wrappers for the List 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 Filter {
    pub active: bool,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct ListItemsRequest {
    name: String,
    filter: Filter,
}

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

#[host_fn]
extern "ExtismHost" {
    fn list_items(input: Json<ListItemsRequest>) -> Json<ListItemsResponse>;
}

/// Calls the list_items host function.
///
/// # Arguments
/// * `name` - String parameter.
/// * `filter` - Filter parameter.
///
/// # Returns
/// The count value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn items(name: &str, filter: Filter) -> Result<i32, Error> {
    let response = unsafe {
        list_items(Json(ListItemsRequest {
            name: name.to_owned(),
            filter: filter,
        }))?
    };

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

    Ok(response.0.count)
}
