use super::request::VoiceListQuery;
use crate::ZaiResult;
use crate::client::ZaiClient;
use validator::Validate;
pub struct VoiceListRequest {
query: VoiceListQuery,
}
impl VoiceListRequest {
pub fn new() -> Self {
Self {
query: VoiceListQuery::new(),
}
}
pub fn validate(&self) -> ZaiResult<()> {
self.query
.validate()
.map_err(crate::client::error::ZaiError::from)?;
Ok(())
}
pub async fn send_via(
&self,
client: &ZaiClient,
) -> ZaiResult<super::response::VoiceListResponse> {
self.validate()?;
let mut query = Vec::with_capacity(2);
if let Some(name) = self.query.voice_name.as_deref() {
query.push(("voiceName", name));
}
if let Some(voice_type) = self.query.voice_type.as_ref() {
query.push(("voiceType", voice_type.as_str()));
}
let route = crate::client::routes::AUDIO_LIST_VOICES;
let url = client
.endpoints()
.resolve_route_with_query(route, &[], &query)?;
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()
}
}