1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait FiatAccountsApi: Send + Sync {
23 async fn deposit_funds_from_linked_dda(
27 &self,
28 params: DepositFundsFromLinkedDdaParams,
29 ) -> Result<models::DepositFundsFromLinkedDdaResponse, Error<DepositFundsFromLinkedDdaError>>;
30
31 async fn get_fiat_account(
36 &self,
37 params: GetFiatAccountParams,
38 ) -> Result<models::FiatAccount, Error<GetFiatAccountError>>;
39
40 async fn get_fiat_accounts(
45 &self,
46 ) -> Result<Vec<models::FiatAccount>, Error<GetFiatAccountsError>>;
47
48 async fn redeem_funds_to_linked_dda(
52 &self,
53 params: RedeemFundsToLinkedDdaParams,
54 ) -> Result<models::RedeemFundsToLinkedDdaResponse, Error<RedeemFundsToLinkedDdaError>>;
55}
56
57pub struct FiatAccountsApiClient {
58 configuration: Arc<configuration::Configuration>,
59}
60
61impl FiatAccountsApiClient {
62 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
63 Self { configuration }
64 }
65}
66
67#[derive(Clone, Debug)]
70#[cfg_attr(feature = "bon", derive(::bon::Builder))]
71pub struct DepositFundsFromLinkedDdaParams {
72 pub account_id: String,
74 pub idempotency_key: Option<String>,
79 pub funds: Option<models::Funds>,
80}
81
82#[derive(Clone, Debug)]
85#[cfg_attr(feature = "bon", derive(::bon::Builder))]
86pub struct GetFiatAccountParams {
87 pub account_id: String,
89}
90
91#[derive(Clone, Debug)]
94#[cfg_attr(feature = "bon", derive(::bon::Builder))]
95pub struct RedeemFundsToLinkedDdaParams {
96 pub account_id: String,
98 pub idempotency_key: Option<String>,
103 pub funds: Option<models::Funds>,
104}
105
106#[async_trait]
107impl FiatAccountsApi for FiatAccountsApiClient {
108 async fn deposit_funds_from_linked_dda(
110 &self,
111 params: DepositFundsFromLinkedDdaParams,
112 ) -> Result<models::DepositFundsFromLinkedDdaResponse, Error<DepositFundsFromLinkedDdaError>>
113 {
114 let DepositFundsFromLinkedDdaParams {
115 account_id,
116 idempotency_key,
117 funds,
118 } = params;
119
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 "{}/fiat_accounts/{accountId}/deposit_from_linked_dda",
126 local_var_configuration.base_path,
127 accountId = crate::apis::urlencode(account_id)
128 );
129 let mut local_var_req_builder =
130 local_var_client.request(reqwest::Method::POST, 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(local_var_param_value) = idempotency_key {
137 local_var_req_builder =
138 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
139 }
140 local_var_req_builder = local_var_req_builder.json(&funds);
141
142 let local_var_req = local_var_req_builder.build()?;
143 let local_var_resp = local_var_client.execute(local_var_req).await?;
144
145 let local_var_status = local_var_resp.status();
146 let local_var_content_type = local_var_resp
147 .headers()
148 .get("content-type")
149 .and_then(|v| v.to_str().ok())
150 .unwrap_or("application/octet-stream");
151 let local_var_content_type = super::ContentType::from(local_var_content_type);
152 let local_var_content = local_var_resp.text().await?;
153
154 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
155 match local_var_content_type {
156 ContentType::Json => {
157 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
158 }
159 ContentType::Text => {
160 return Err(Error::from(serde_json::Error::custom(
161 "Received `text/plain` content type response that cannot be converted to \
162 `models::DepositFundsFromLinkedDdaResponse`",
163 )));
164 }
165 ContentType::Unsupported(local_var_unknown_type) => {
166 return Err(Error::from(serde_json::Error::custom(format!(
167 "Received `{local_var_unknown_type}` content type response that cannot be \
168 converted to `models::DepositFundsFromLinkedDdaResponse`"
169 ))));
170 }
171 }
172 } else {
173 let local_var_entity: Option<DepositFundsFromLinkedDdaError> =
174 serde_json::from_str(&local_var_content).ok();
175 let local_var_error = ResponseContent {
176 status: local_var_status,
177 content: local_var_content,
178 entity: local_var_entity,
179 };
180 Err(Error::ResponseError(local_var_error))
181 }
182 }
183
184 async fn get_fiat_account(
187 &self,
188 params: GetFiatAccountParams,
189 ) -> Result<models::FiatAccount, Error<GetFiatAccountError>> {
190 let GetFiatAccountParams { account_id } = params;
191
192 let local_var_configuration = &self.configuration;
193
194 let local_var_client = &local_var_configuration.client;
195
196 let local_var_uri_str = format!(
197 "{}/fiat_accounts/{accountId}",
198 local_var_configuration.base_path,
199 accountId = crate::apis::urlencode(account_id)
200 );
201 let mut local_var_req_builder =
202 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
203
204 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
205 local_var_req_builder = local_var_req_builder
206 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
207 }
208
209 let local_var_req = local_var_req_builder.build()?;
210 let local_var_resp = local_var_client.execute(local_var_req).await?;
211
212 let local_var_status = local_var_resp.status();
213 let local_var_content_type = local_var_resp
214 .headers()
215 .get("content-type")
216 .and_then(|v| v.to_str().ok())
217 .unwrap_or("application/octet-stream");
218 let local_var_content_type = super::ContentType::from(local_var_content_type);
219 let local_var_content = local_var_resp.text().await?;
220
221 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
222 match local_var_content_type {
223 ContentType::Json => {
224 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
225 }
226 ContentType::Text => {
227 return Err(Error::from(serde_json::Error::custom(
228 "Received `text/plain` content type response that cannot be converted to \
229 `models::FiatAccount`",
230 )));
231 }
232 ContentType::Unsupported(local_var_unknown_type) => {
233 return Err(Error::from(serde_json::Error::custom(format!(
234 "Received `{local_var_unknown_type}` content type response that cannot be \
235 converted to `models::FiatAccount`"
236 ))));
237 }
238 }
239 } else {
240 let local_var_entity: Option<GetFiatAccountError> =
241 serde_json::from_str(&local_var_content).ok();
242 let local_var_error = ResponseContent {
243 status: local_var_status,
244 content: local_var_content,
245 entity: local_var_entity,
246 };
247 Err(Error::ResponseError(local_var_error))
248 }
249 }
250
251 async fn get_fiat_accounts(
254 &self,
255 ) -> Result<Vec<models::FiatAccount>, Error<GetFiatAccountsError>> {
256 let local_var_configuration = &self.configuration;
257
258 let local_var_client = &local_var_configuration.client;
259
260 let local_var_uri_str = format!("{}/fiat_accounts", local_var_configuration.base_path);
261 let mut local_var_req_builder =
262 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
263
264 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
265 local_var_req_builder = local_var_req_builder
266 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
267 }
268
269 let local_var_req = local_var_req_builder.build()?;
270 let local_var_resp = local_var_client.execute(local_var_req).await?;
271
272 let local_var_status = local_var_resp.status();
273 let local_var_content_type = local_var_resp
274 .headers()
275 .get("content-type")
276 .and_then(|v| v.to_str().ok())
277 .unwrap_or("application/octet-stream");
278 let local_var_content_type = super::ContentType::from(local_var_content_type);
279 let local_var_content = local_var_resp.text().await?;
280
281 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
282 match local_var_content_type {
283 ContentType::Json => {
284 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
285 }
286 ContentType::Text => {
287 return Err(Error::from(serde_json::Error::custom(
288 "Received `text/plain` content type response that cannot be converted to \
289 `Vec<models::FiatAccount>`",
290 )));
291 }
292 ContentType::Unsupported(local_var_unknown_type) => {
293 return Err(Error::from(serde_json::Error::custom(format!(
294 "Received `{local_var_unknown_type}` content type response that cannot be \
295 converted to `Vec<models::FiatAccount>`"
296 ))));
297 }
298 }
299 } else {
300 let local_var_entity: Option<GetFiatAccountsError> =
301 serde_json::from_str(&local_var_content).ok();
302 let local_var_error = ResponseContent {
303 status: local_var_status,
304 content: local_var_content,
305 entity: local_var_entity,
306 };
307 Err(Error::ResponseError(local_var_error))
308 }
309 }
310
311 async fn redeem_funds_to_linked_dda(
313 &self,
314 params: RedeemFundsToLinkedDdaParams,
315 ) -> Result<models::RedeemFundsToLinkedDdaResponse, Error<RedeemFundsToLinkedDdaError>> {
316 let RedeemFundsToLinkedDdaParams {
317 account_id,
318 idempotency_key,
319 funds,
320 } = params;
321
322 let local_var_configuration = &self.configuration;
323
324 let local_var_client = &local_var_configuration.client;
325
326 let local_var_uri_str = format!(
327 "{}/fiat_accounts/{accountId}/redeem_to_linked_dda",
328 local_var_configuration.base_path,
329 accountId = crate::apis::urlencode(account_id)
330 );
331 let mut local_var_req_builder =
332 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
333
334 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
335 local_var_req_builder = local_var_req_builder
336 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
337 }
338 if let Some(local_var_param_value) = idempotency_key {
339 local_var_req_builder =
340 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
341 }
342 local_var_req_builder = local_var_req_builder.json(&funds);
343
344 let local_var_req = local_var_req_builder.build()?;
345 let local_var_resp = local_var_client.execute(local_var_req).await?;
346
347 let local_var_status = local_var_resp.status();
348 let local_var_content_type = local_var_resp
349 .headers()
350 .get("content-type")
351 .and_then(|v| v.to_str().ok())
352 .unwrap_or("application/octet-stream");
353 let local_var_content_type = super::ContentType::from(local_var_content_type);
354 let local_var_content = local_var_resp.text().await?;
355
356 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
357 match local_var_content_type {
358 ContentType::Json => {
359 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
360 }
361 ContentType::Text => {
362 return Err(Error::from(serde_json::Error::custom(
363 "Received `text/plain` content type response that cannot be converted to \
364 `models::RedeemFundsToLinkedDdaResponse`",
365 )));
366 }
367 ContentType::Unsupported(local_var_unknown_type) => {
368 return Err(Error::from(serde_json::Error::custom(format!(
369 "Received `{local_var_unknown_type}` content type response that cannot be \
370 converted to `models::RedeemFundsToLinkedDdaResponse`"
371 ))));
372 }
373 }
374 } else {
375 let local_var_entity: Option<RedeemFundsToLinkedDdaError> =
376 serde_json::from_str(&local_var_content).ok();
377 let local_var_error = ResponseContent {
378 status: local_var_status,
379 content: local_var_content,
380 entity: local_var_entity,
381 };
382 Err(Error::ResponseError(local_var_error))
383 }
384 }
385}
386
387#[derive(Debug, Clone, Serialize, Deserialize)]
390#[serde(untagged)]
391pub enum DepositFundsFromLinkedDdaError {
392 DefaultResponse(models::ErrorSchema),
393 UnknownValue(serde_json::Value),
394}
395
396#[derive(Debug, Clone, Serialize, Deserialize)]
398#[serde(untagged)]
399pub enum GetFiatAccountError {
400 DefaultResponse(models::ErrorSchema),
401 UnknownValue(serde_json::Value),
402}
403
404#[derive(Debug, Clone, Serialize, Deserialize)]
406#[serde(untagged)]
407pub enum GetFiatAccountsError {
408 DefaultResponse(models::ErrorSchema),
409 UnknownValue(serde_json::Value),
410}
411
412#[derive(Debug, Clone, Serialize, Deserialize)]
415#[serde(untagged)]
416pub enum RedeemFundsToLinkedDdaError {
417 DefaultResponse(models::ErrorSchema),
418 UnknownValue(serde_json::Value),
419}