use validator::Validate;
use super::{super::traits::*, request::VoiceCloneBody};
use crate::client::ZaiClient;
pub struct VoiceCloneRequest<N>
where
N: VoiceClone,
{
body: VoiceCloneBody<N>,
}
impl<N> VoiceCloneRequest<N>
where
N: VoiceClone,
{
pub fn new(
model: N,
voice_name: impl Into<String>,
input: impl Into<String>,
file_id: impl Into<String>,
) -> Self {
let body = VoiceCloneBody::new(model, voice_name, input, file_id);
Self { body }
}
pub fn body_mut(&mut self) -> &mut VoiceCloneBody<N> {
&mut self.body
}
pub fn with_text(mut self, text: impl Into<String>) -> Self {
self.body = self.body.with_text(text);
self
}
pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
self.body = self.body.with_request_id(request_id);
self
}
pub fn validate(&self) -> crate::ZaiResult<()> {
self.body
.validate()
.map_err(crate::client::error::ZaiError::from)?;
Ok(())
}
pub async fn send_via(
&self,
client: &ZaiClient,
) -> crate::ZaiResult<super::response::VoiceCloneResponse> {
self.validate()?;
let route = crate::client::routes::AUDIO_CLONE_VOICE;
let url = client.endpoints().resolve_route(route, &[])?;
client
.send_json::<_, super::response::VoiceCloneResponse>(route.method(), url, &self.body)
.await
}
}