use extism_pdk::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MatchOptions {
#[serde(default)]
pub username: String,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct MatcherMatchSongsRequest {
songs: Vec<nd_pdk_types::SongRef>,
opts: MatchOptions,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
struct MatcherMatchSongsResponse {
#[serde(default)]
results: Vec<Option<nd_pdk_types::Track>>,
#[serde(default)]
error: Option<String>,
}
#[host_fn]
extern "ExtismHost" {
fn matcher_matchsongs(input: Json<MatcherMatchSongsRequest>) -> Json<MatcherMatchSongsResponse>;
}
pub fn match_songs(songs: Vec<nd_pdk_types::SongRef>, opts: MatchOptions) -> Result<Vec<Option<nd_pdk_types::Track>>, Error> {
let response = unsafe {
matcher_matchsongs(Json(MatcherMatchSongsRequest {
songs: songs,
opts: opts,
}))?
};
if let Some(err) = response.0.error {
return Err(Error::msg(err));
}
Ok(response.0.results)
}