1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait ProvidersApi: Send + Sync {
29 async fn delete<'a>(&self, id: uuid::Uuid) -> Result<(), Error<DeleteError>>;
31
32 async fn get<'a>(
34 &self,
35 id: uuid::Uuid,
36 ) -> Result<models::ProviderResponseModel, Error<GetError>>;
37
38 async fn post_delete_recover_token<'a>(
40 &self,
41 id: uuid::Uuid,
42 provider_verify_delete_recover_request_model: Option<
43 models::ProviderVerifyDeleteRecoverRequestModel,
44 >,
45 ) -> Result<(), Error<PostDeleteRecoverTokenError>>;
46
47 async fn put<'a>(
49 &self,
50 id: uuid::Uuid,
51 provider_update_request_model: Option<models::ProviderUpdateRequestModel>,
52 ) -> Result<models::ProviderResponseModel, Error<PutError>>;
53
54 async fn setup<'a>(
56 &self,
57 id: uuid::Uuid,
58 provider_setup_request_model: Option<models::ProviderSetupRequestModel>,
59 ) -> Result<models::ProviderResponseModel, Error<SetupError>>;
60}
61
62pub struct ProvidersApiClient {
63 configuration: Arc<configuration::Configuration>,
64}
65
66impl ProvidersApiClient {
67 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
68 Self { configuration }
69 }
70}
71
72#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
73#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
74impl ProvidersApi for ProvidersApiClient {
75 async fn delete<'a>(&self, id: uuid::Uuid) -> Result<(), Error<DeleteError>> {
76 let local_var_configuration = &self.configuration;
77
78 let local_var_client = &local_var_configuration.client;
79
80 let local_var_uri_str = format!(
81 "{}/providers/{id}",
82 local_var_configuration.base_path,
83 id = id
84 );
85 let mut local_var_req_builder =
86 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
87
88 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
89 local_var_req_builder = local_var_req_builder
90 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
91 }
92 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
93 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
94 };
95
96 let local_var_req = local_var_req_builder.build()?;
97 let local_var_resp = local_var_client.execute(local_var_req).await?;
98
99 let local_var_status = local_var_resp.status();
100 let local_var_content = local_var_resp.text().await?;
101
102 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
103 Ok(())
104 } else {
105 let local_var_entity: Option<DeleteError> =
106 serde_json::from_str(&local_var_content).ok();
107 let local_var_error = ResponseContent {
108 status: local_var_status,
109 content: local_var_content,
110 entity: local_var_entity,
111 };
112 Err(Error::ResponseError(local_var_error))
113 }
114 }
115
116 async fn get<'a>(
117 &self,
118 id: uuid::Uuid,
119 ) -> Result<models::ProviderResponseModel, Error<GetError>> {
120 let local_var_configuration = &self.configuration;
121
122 let local_var_client = &local_var_configuration.client;
123
124 let local_var_uri_str = format!(
125 "{}/providers/{id}",
126 local_var_configuration.base_path,
127 id = id
128 );
129 let mut local_var_req_builder =
130 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
131
132 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
133 local_var_req_builder = local_var_req_builder
134 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
135 }
136 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
137 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
138 };
139
140 let local_var_req = local_var_req_builder.build()?;
141 let local_var_resp = local_var_client.execute(local_var_req).await?;
142
143 let local_var_status = local_var_resp.status();
144 let local_var_content_type = local_var_resp
145 .headers()
146 .get("content-type")
147 .and_then(|v| v.to_str().ok())
148 .unwrap_or("application/octet-stream");
149 let local_var_content_type = super::ContentType::from(local_var_content_type);
150 let local_var_content = local_var_resp.text().await?;
151
152 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153 match local_var_content_type {
154 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
155 ContentType::Text => {
156 return Err(Error::from(serde_json::Error::custom(
157 "Received `text/plain` content type response that cannot be converted to `models::ProviderResponseModel`",
158 )));
159 }
160 ContentType::Unsupported(local_var_unknown_type) => {
161 return Err(Error::from(serde_json::Error::custom(format!(
162 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProviderResponseModel`"
163 ))));
164 }
165 }
166 } else {
167 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
168 let local_var_error = ResponseContent {
169 status: local_var_status,
170 content: local_var_content,
171 entity: local_var_entity,
172 };
173 Err(Error::ResponseError(local_var_error))
174 }
175 }
176
177 async fn post_delete_recover_token<'a>(
178 &self,
179 id: uuid::Uuid,
180 provider_verify_delete_recover_request_model: Option<
181 models::ProviderVerifyDeleteRecoverRequestModel,
182 >,
183 ) -> Result<(), Error<PostDeleteRecoverTokenError>> {
184 let local_var_configuration = &self.configuration;
185
186 let local_var_client = &local_var_configuration.client;
187
188 let local_var_uri_str = format!(
189 "{}/providers/{id}/delete-recover-token",
190 local_var_configuration.base_path,
191 id = id
192 );
193 let mut local_var_req_builder =
194 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
195
196 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
197 local_var_req_builder = local_var_req_builder
198 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199 }
200 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
201 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
202 };
203 local_var_req_builder =
204 local_var_req_builder.json(&provider_verify_delete_recover_request_model);
205
206 let local_var_req = local_var_req_builder.build()?;
207 let local_var_resp = local_var_client.execute(local_var_req).await?;
208
209 let local_var_status = local_var_resp.status();
210 let local_var_content = local_var_resp.text().await?;
211
212 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
213 Ok(())
214 } else {
215 let local_var_entity: Option<PostDeleteRecoverTokenError> =
216 serde_json::from_str(&local_var_content).ok();
217 let local_var_error = ResponseContent {
218 status: local_var_status,
219 content: local_var_content,
220 entity: local_var_entity,
221 };
222 Err(Error::ResponseError(local_var_error))
223 }
224 }
225
226 async fn put<'a>(
227 &self,
228 id: uuid::Uuid,
229 provider_update_request_model: Option<models::ProviderUpdateRequestModel>,
230 ) -> Result<models::ProviderResponseModel, Error<PutError>> {
231 let local_var_configuration = &self.configuration;
232
233 let local_var_client = &local_var_configuration.client;
234
235 let local_var_uri_str = format!(
236 "{}/providers/{id}",
237 local_var_configuration.base_path,
238 id = id
239 );
240 let mut local_var_req_builder =
241 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
242
243 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
244 local_var_req_builder = local_var_req_builder
245 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
246 }
247 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
248 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
249 };
250 local_var_req_builder = local_var_req_builder.json(&provider_update_request_model);
251
252 let local_var_req = local_var_req_builder.build()?;
253 let local_var_resp = local_var_client.execute(local_var_req).await?;
254
255 let local_var_status = local_var_resp.status();
256 let local_var_content_type = local_var_resp
257 .headers()
258 .get("content-type")
259 .and_then(|v| v.to_str().ok())
260 .unwrap_or("application/octet-stream");
261 let local_var_content_type = super::ContentType::from(local_var_content_type);
262 let local_var_content = local_var_resp.text().await?;
263
264 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
265 match local_var_content_type {
266 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
267 ContentType::Text => {
268 return Err(Error::from(serde_json::Error::custom(
269 "Received `text/plain` content type response that cannot be converted to `models::ProviderResponseModel`",
270 )));
271 }
272 ContentType::Unsupported(local_var_unknown_type) => {
273 return Err(Error::from(serde_json::Error::custom(format!(
274 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProviderResponseModel`"
275 ))));
276 }
277 }
278 } else {
279 let local_var_entity: Option<PutError> = serde_json::from_str(&local_var_content).ok();
280 let local_var_error = ResponseContent {
281 status: local_var_status,
282 content: local_var_content,
283 entity: local_var_entity,
284 };
285 Err(Error::ResponseError(local_var_error))
286 }
287 }
288
289 async fn setup<'a>(
290 &self,
291 id: uuid::Uuid,
292 provider_setup_request_model: Option<models::ProviderSetupRequestModel>,
293 ) -> Result<models::ProviderResponseModel, Error<SetupError>> {
294 let local_var_configuration = &self.configuration;
295
296 let local_var_client = &local_var_configuration.client;
297
298 let local_var_uri_str = format!(
299 "{}/providers/{id}/setup",
300 local_var_configuration.base_path,
301 id = id
302 );
303 let mut local_var_req_builder =
304 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
305
306 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
307 local_var_req_builder = local_var_req_builder
308 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
309 }
310 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
311 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
312 };
313 local_var_req_builder = local_var_req_builder.json(&provider_setup_request_model);
314
315 let local_var_req = local_var_req_builder.build()?;
316 let local_var_resp = local_var_client.execute(local_var_req).await?;
317
318 let local_var_status = local_var_resp.status();
319 let local_var_content_type = local_var_resp
320 .headers()
321 .get("content-type")
322 .and_then(|v| v.to_str().ok())
323 .unwrap_or("application/octet-stream");
324 let local_var_content_type = super::ContentType::from(local_var_content_type);
325 let local_var_content = local_var_resp.text().await?;
326
327 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
328 match local_var_content_type {
329 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
330 ContentType::Text => {
331 return Err(Error::from(serde_json::Error::custom(
332 "Received `text/plain` content type response that cannot be converted to `models::ProviderResponseModel`",
333 )));
334 }
335 ContentType::Unsupported(local_var_unknown_type) => {
336 return Err(Error::from(serde_json::Error::custom(format!(
337 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProviderResponseModel`"
338 ))));
339 }
340 }
341 } else {
342 let local_var_entity: Option<SetupError> =
343 serde_json::from_str(&local_var_content).ok();
344 let local_var_error = ResponseContent {
345 status: local_var_status,
346 content: local_var_content,
347 entity: local_var_entity,
348 };
349 Err(Error::ResponseError(local_var_error))
350 }
351 }
352}
353
354#[derive(Debug, Clone, Serialize, Deserialize)]
356#[serde(untagged)]
357pub enum DeleteError {
358 UnknownValue(serde_json::Value),
359}
360#[derive(Debug, Clone, Serialize, Deserialize)]
362#[serde(untagged)]
363pub enum GetError {
364 UnknownValue(serde_json::Value),
365}
366#[derive(Debug, Clone, Serialize, Deserialize)]
368#[serde(untagged)]
369pub enum PostDeleteRecoverTokenError {
370 UnknownValue(serde_json::Value),
371}
372#[derive(Debug, Clone, Serialize, Deserialize)]
374#[serde(untagged)]
375pub enum PutError {
376 UnknownValue(serde_json::Value),
377}
378#[derive(Debug, Clone, Serialize, Deserialize)]
380#[serde(untagged)]
381pub enum SetupError {
382 UnknownValue(serde_json::Value),
383}