1use std::sync::Arc;
2
3use crate::client::{
4 endpoints::{ApiBase, EndpointConfig, join_url, paths},
5 http::{HttpClient, HttpClientConfig, parse_typed_response},
6};
7
8pub struct FileDeleteRequest {
10 pub key: String,
11 url: String,
12 endpoint_config: EndpointConfig,
13 api_base: ApiBase,
14 file_id: String,
15 http_config: Arc<HttpClientConfig>,
16 _body: (),
17}
18
19impl FileDeleteRequest {
20 pub fn new(key: String, file_id: impl Into<String>) -> Self {
21 let file_id = file_id.into();
22 let endpoint_config = EndpointConfig::default();
23 let api_base = ApiBase::PaasV4;
24 let url = endpoint_config.url(&api_base, &join_url(paths::FILES, &file_id));
25 Self {
26 key,
27 url,
28 endpoint_config,
29 api_base,
30 file_id,
31 http_config: Arc::new(HttpClientConfig::default()),
32 _body: (),
33 }
34 }
35
36 fn rebuild_url(&mut self) {
37 self.url = self
38 .endpoint_config
39 .url(&self.api_base, &join_url(paths::FILES, &self.file_id));
40 }
41
42 pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
43 self.api_base = ApiBase::Custom(base_url.into());
44 self.rebuild_url();
45 self
46 }
47
48 pub fn with_endpoint_config(mut self, endpoint_config: EndpointConfig) -> Self {
49 self.endpoint_config = endpoint_config;
50 self.rebuild_url();
51 self
52 }
53
54 pub fn with_http_config(mut self, config: HttpClientConfig) -> Self {
55 self.http_config = Arc::new(config);
56 self
57 }
58
59 pub fn delete(
60 &self,
61 ) -> impl std::future::Future<Output = crate::ZaiResult<reqwest::Response>> + Send {
62 HttpClient::delete(self)
63 }
64
65 pub async fn send(&self) -> crate::ZaiResult<super::response::FileDeleteResponse> {
67 let resp = self.delete().await?;
68 parse_typed_response::<super::response::FileDeleteResponse>(resp).await
69 }
70}
71
72impl HttpClient for FileDeleteRequest {
73 type Body = ();
74 type ApiUrl = String;
75 type ApiKey = String;
76
77 fn api_url(&self) -> &Self::ApiUrl {
78 &self.url
79 }
80 fn api_key(&self) -> &Self::ApiKey {
81 &self.key
82 }
83 fn body(&self) -> &Self::Body {
84 &self._body
85 }
86
87 fn http_config(&self) -> Arc<HttpClientConfig> {
88 self.http_config.clone()
89 }
90}