zai_rs/model/voice_delete/
data.rs1use std::sync::Arc;
2
3use validator::Validate;
4
5use super::request::VoiceDeleteBody;
6use crate::client::{
7 endpoints::{ApiBase, EndpointConfig, paths},
8 http::{HttpClient, HttpClientConfig, parse_typed_response},
9};
10
11pub struct VoiceDeleteRequest {
13 pub key: String,
14 url: String,
15 endpoint_config: EndpointConfig,
16 api_base: ApiBase,
17 http_config: Arc<HttpClientConfig>,
18 body: VoiceDeleteBody,
19}
20
21impl VoiceDeleteRequest {
22 pub fn new(key: String, voice: impl Into<String>) -> Self {
23 let body = VoiceDeleteBody::new(voice);
24 let endpoint_config = EndpointConfig::default();
25 let api_base = ApiBase::PaasV4;
26 let url = endpoint_config.url(&api_base, paths::VOICE_DELETE);
27 Self {
28 key,
29 url,
30 endpoint_config,
31 api_base,
32 http_config: Arc::new(HttpClientConfig::default()),
33 body,
34 }
35 }
36
37 fn rebuild_url(&mut self) {
38 self.url = self
39 .endpoint_config
40 .url(&self.api_base, paths::VOICE_DELETE);
41 }
42
43 pub fn with_base_url(mut self, base: impl Into<String>) -> Self {
44 self.api_base = ApiBase::Custom(base.into());
45 self.rebuild_url();
46 self
47 }
48
49 pub fn with_endpoint_config(mut self, endpoint_config: EndpointConfig) -> Self {
50 self.endpoint_config = endpoint_config;
51 self.rebuild_url();
52 self
53 }
54
55 pub fn with_http_config(mut self, config: HttpClientConfig) -> Self {
56 self.http_config = Arc::new(config);
57 self
58 }
59
60 pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
61 self.body = self.body.with_request_id(request_id);
62 self
63 }
64
65 pub fn validate(&self) -> crate::ZaiResult<()> {
66 self.body
67 .validate()
68 .map_err(|e| crate::client::error::ZaiError::ApiError {
69 code: 1200,
70 message: format!("Validation error: {:?}", e),
71 })?;
72 Ok(())
73 }
74
75 pub async fn send(&self) -> crate::ZaiResult<super::response::VoiceDeleteResponse> {
76 self.validate()?;
77 let resp = self.post().await?;
78 let parsed = parse_typed_response::<super::response::VoiceDeleteResponse>(resp).await?;
79 Ok(parsed)
80 }
81}
82
83impl HttpClient for VoiceDeleteRequest {
84 type Body = VoiceDeleteBody;
85 type ApiUrl = String;
86 type ApiKey = String;
87
88 fn api_url(&self) -> &Self::ApiUrl {
89 &self.url
90 }
91 fn api_key(&self) -> &Self::ApiKey {
92 &self.key
93 }
94 fn body(&self) -> &Self::Body {
95 &self.body
96 }
97
98 fn http_config(&self) -> Arc<HttpClientConfig> {
99 Arc::clone(&self.http_config)
100 }
101}