use super::request::VoiceListQuery;
use crate::ZaiResult;
use crate::client::ZaiClient;
pub struct VoiceListRequest {
query: VoiceListQuery,
}
impl VoiceListRequest {
pub fn new() -> Self {
Self {
query: VoiceListQuery::new(),
}
}
pub fn validate(&self) -> ZaiResult<()> {
Ok(())
}
pub async fn send_via(
&self,
client: &ZaiClient,
) -> ZaiResult<super::response::VoiceListResponse> {
self.validate()?;
let mut params: Vec<(&str, String)> = Vec::new();
if let Some(ref n) = self.query.voice_name {
params.push(("voiceName", n.clone()));
}
if let Some(ref t) = self.query.voice_type {
params.push(("voiceType", t.as_str().to_string()));
}
let owned: Vec<(String, String)> = params
.iter()
.map(|(k, v)| ((*k).to_string(), v.clone()))
.collect();
let query_refs: Vec<(&str, &str)> = owned
.iter()
.map(|(k, v)| (k.as_str(), v.as_str()))
.collect();
let route = crate::client::routes::AUDIO_LIST_VOICES;
let url = client
.endpoints()
.resolve_route_with_query(route, &[], &query_refs)?;
client
.send_empty::<super::response::VoiceListResponse>(route.method(), url)
.await
}
pub fn with_query(mut self, q: VoiceListQuery) -> Self {
self.query = q;
self
}
}
impl Default for VoiceListRequest {
fn default() -> Self {
Self::new()
}
}