// Code generated by ndpgen. DO NOT EDIT.
//
// This file contains client wrappers for the Artwork 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 ArtworkGetArtistUrlRequest {
    id: String,
    size: i32,
}

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

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

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

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

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

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

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

#[host_fn]
extern "ExtismHost" {
    fn artwork_getartisturl(input: Json<ArtworkGetArtistUrlRequest>) -> Json<ArtworkGetArtistUrlResponse>;
    fn artwork_getalbumurl(input: Json<ArtworkGetAlbumUrlRequest>) -> Json<ArtworkGetAlbumUrlResponse>;
    fn artwork_gettrackurl(input: Json<ArtworkGetTrackUrlRequest>) -> Json<ArtworkGetTrackUrlResponse>;
    fn artwork_getplaylisturl(input: Json<ArtworkGetPlaylistUrlRequest>) -> Json<ArtworkGetPlaylistUrlResponse>;
}

/// GetArtistUrl generates a public URL for an artist's artwork.
/// 
/// Parameters:
///   - id: The artist's unique identifier
///   - size: Desired image size in pixels (0 for original size)
/// 
/// Returns the public URL for the artwork, or an error if generation fails.
///
/// # Arguments
/// * `id` - String parameter.
/// * `size` - i32 parameter.
///
/// # Returns
/// The url value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_artist_url(id: &str, size: i32) -> Result<String, Error> {
    let response = unsafe {
        artwork_getartisturl(Json(ArtworkGetArtistUrlRequest {
            id: id.to_owned(),
            size: size,
        }))?
    };

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

    Ok(response.0.url)
}

/// GetAlbumUrl generates a public URL for an album's artwork.
/// 
/// Parameters:
///   - id: The album's unique identifier
///   - size: Desired image size in pixels (0 for original size)
/// 
/// Returns the public URL for the artwork, or an error if generation fails.
///
/// # Arguments
/// * `id` - String parameter.
/// * `size` - i32 parameter.
///
/// # Returns
/// The url value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_album_url(id: &str, size: i32) -> Result<String, Error> {
    let response = unsafe {
        artwork_getalbumurl(Json(ArtworkGetAlbumUrlRequest {
            id: id.to_owned(),
            size: size,
        }))?
    };

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

    Ok(response.0.url)
}

/// GetTrackUrl generates a public URL for a track's artwork.
/// 
/// Parameters:
///   - id: The track's (media file) unique identifier
///   - size: Desired image size in pixels (0 for original size)
/// 
/// Returns the public URL for the artwork, or an error if generation fails.
///
/// # Arguments
/// * `id` - String parameter.
/// * `size` - i32 parameter.
///
/// # Returns
/// The url value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_track_url(id: &str, size: i32) -> Result<String, Error> {
    let response = unsafe {
        artwork_gettrackurl(Json(ArtworkGetTrackUrlRequest {
            id: id.to_owned(),
            size: size,
        }))?
    };

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

    Ok(response.0.url)
}

/// GetPlaylistUrl generates a public URL for a playlist's artwork.
/// 
/// Parameters:
///   - id: The playlist's unique identifier
///   - size: Desired image size in pixels (0 for original size)
/// 
/// Returns the public URL for the artwork, or an error if generation fails.
///
/// # Arguments
/// * `id` - String parameter.
/// * `size` - i32 parameter.
///
/// # Returns
/// The url value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_playlist_url(id: &str, size: i32) -> Result<String, Error> {
    let response = unsafe {
        artwork_getplaylisturl(Json(ArtworkGetPlaylistUrlRequest {
            id: id.to_owned(),
            size: size,
        }))?
    };

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

    Ok(response.0.url)
}
