🏡 index : ironmagma/quintodrome.git

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

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

/// Library represents a music library with metadata.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Library {
    pub id: i32,
    pub name: String,
    #[serde(default)]
    pub path: String,
    #[serde(default)]
    pub mount_point: String,
    pub last_scan_at: i64,
    pub total_songs: i32,
    pub total_albums: i32,
    pub total_artists: i32,
    pub total_size: i64,
    pub total_duration: f64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct LibraryGetLibraryRequest {
    id: i32,
}

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

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

#[host_fn]
extern "ExtismHost" {
    fn library_getlibrary(input: Json<LibraryGetLibraryRequest>) -> Json<LibraryGetLibraryResponse>;
    fn library_getalllibraries(input: Json<serde_json::Value>) -> Json<LibraryGetAllLibrariesResponse>;
}

/// GetLibrary retrieves metadata for a specific library by ID.
/// 
/// Parameters:
///   - id: The library's unique identifier
/// 
/// Returns the library metadata, or an error if the library is not found.
///
/// # Arguments
/// * `id` - i32 parameter.
///
/// # Returns
/// The result value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_library(id: i32) -> Result<Option<Library>, Error> {
    let response = unsafe {
        library_getlibrary(Json(LibraryGetLibraryRequest {
            id: id,
        }))?
    };

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

    Ok(response.0.result)
}

/// GetAllLibraries retrieves metadata for all configured libraries.
/// 
/// Returns a slice of all libraries with their metadata.
///
/// # Returns
/// The result value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_all_libraries() -> Result<Vec<Library>, Error> {
    let response = unsafe {
        library_getalllibraries(Json(serde_json::json!({})))?
    };

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

    Ok(response.0.result)
}