use validator::Validate;
use super::{
super::traits::*,
video_request::{Fps, ImageUrl, VideoBody, VideoDuration, VideoQuality, VideoSize},
};
use crate::{client::ZaiClient, model::async_chat_get::AsyncResponse};
pub struct VideoGenRequest<N>
where
N: VideoGen,
{
body: VideoBody<N>,
}
impl<N> VideoGenRequest<N>
where
N: VideoGen,
{
pub fn new(model: N) -> Self {
let body = VideoBody::new(model);
Self { body }
}
pub fn with_prompt(mut self, prompt: impl Into<String>) -> Self {
self.body = self.body.with_prompt(prompt);
self
}
pub fn with_quality(mut self, quality: VideoQuality) -> Self {
self.body = self.body.with_quality(quality);
self
}
pub fn with_audio(mut self, with_audio: bool) -> Self {
self.body = self.body.with_audio(with_audio);
self
}
pub fn with_watermark_enabled(mut self, watermark_enabled: bool) -> Self {
self.body = self.body.with_watermark_enabled(watermark_enabled);
self
}
pub fn with_image_url(mut self, image_url: ImageUrl) -> Self {
self.body = self.body.with_image_url(image_url);
self
}
pub fn with_size(mut self, size: VideoSize) -> Self {
self.body = self.body.with_size(size);
self
}
pub fn with_fps(mut self, fps: Fps) -> Self {
self.body = self.body.with_fps(fps);
self
}
pub fn with_duration(mut self, duration: VideoDuration) -> Self {
self.body = self.body.with_duration(duration);
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 with_user_id(mut self, user_id: impl Into<String>) -> Self {
self.body = self.body.with_user_id(user_id);
self
}
}
impl<N> VideoGenRequest<N>
where
N: VideoGen,
{
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<AsyncResponse> {
self.validate()?;
let route = crate::client::routes::VIDEOS_GENERATE;
let url = client.endpoints().resolve_route(route, &[])?;
let response = client
.send_json::<_, AsyncResponse>(route.method(), url, &self.body)
.await?;
response.validate()?;
Ok(response)
}
}