Skip to main content

zai_rs/model/voice_delete/
data.rs

1use validator::Validate;
2
3use super::request::VoiceDeleteBody;
4use crate::client::http::HttpClient;
5
6/// Voice delete request using JSON body
7pub struct VoiceDeleteRequest {
8    pub key: String,
9    body: VoiceDeleteBody,
10}
11
12impl VoiceDeleteRequest {
13    pub fn new(key: String, voice: impl Into<String>) -> Self {
14        let body = VoiceDeleteBody::new(voice);
15        Self { key, body }
16    }
17
18    pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
19        self.body = self.body.with_request_id(request_id);
20        self
21    }
22
23    pub fn validate(&self) -> crate::ZaiResult<()> {
24        self.body
25            .validate()
26            .map_err(|e| crate::client::error::ZaiError::ApiError {
27                code: 1200,
28                message: format!("Validation error: {:?}", e),
29            })?;
30        Ok(())
31    }
32
33    pub async fn send(&self) -> crate::ZaiResult<super::response::VoiceDeleteResponse> {
34        self.validate()?;
35        let resp = self.post().await?;
36        let parsed = resp.json::<super::response::VoiceDeleteResponse>().await?;
37        Ok(parsed)
38    }
39}
40
41impl HttpClient for VoiceDeleteRequest {
42    type Body = VoiceDeleteBody;
43    type ApiUrl = &'static str;
44    type ApiKey = String;
45
46    fn api_url(&self) -> &Self::ApiUrl {
47        &"https://open.bigmodel.cn/api/paas/v4/voice/delete"
48    }
49    fn api_key(&self) -> &Self::ApiKey {
50        &self.key
51    }
52    fn body(&self) -> &Self::Body {
53        &self.body
54    }
55}