brevo/apis/
balance_api.rs

1/*
2 * Brevo API
3 *
4 * Brevo provide a RESTFul API that can be used with any languages. With this API, you will be able to :   - Manage your campaigns and get the statistics   - Manage your contacts   - Send transactional Emails and SMS   - and much more...  You can download our wrappers at https://github.com/orgs/brevo  **Possible responses**   | Code | Message |   | :-------------: | ------------- |   | 200  | OK. Successful Request  |   | 201  | OK. Successful Creation |   | 202  | OK. Request accepted |   | 204  | OK. Successful Update/Deletion  |   | 400  | Error. Bad Request  |   | 401  | Error. Authentication Needed  |   | 402  | Error. Not enough credit, plan upgrade needed  |   | 403  | Error. Permission denied  |   | 404  | Error. Object does not exist |   | 405  | Error. Method not allowed  |   | 406  | Error. Not Acceptable  |   | 422  | Error. Unprocessable Entity |
5 *
6 * The version of the OpenAPI document: 3.0.0
7 * Contact: contact@brevo.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`begin_transaction`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum BeginTransactionError {
20    Status401(models::ErrorResponse),
21    Status403(models::ErrorResponse),
22    Status404(models::ErrorResponse),
23    Status422(models::ErrorResponse),
24    Status500(models::ErrorResponse),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`cancel_transaction`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CancelTransactionError {
32    Status401(models::ErrorResponse),
33    Status403(models::ErrorResponse),
34    Status404(models::ErrorResponse),
35    Status422(models::ErrorResponse),
36    Status500(models::ErrorResponse),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`complete_transaction`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum CompleteTransactionError {
44    Status401(models::ErrorResponse),
45    Status403(models::ErrorResponse),
46    Status404(models::ErrorResponse),
47    Status422(models::ErrorResponse),
48    Status500(models::ErrorResponse),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`create_balance_limit`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum CreateBalanceLimitError {
56    Status401(models::ErrorResponse),
57    Status403(models::ErrorResponse),
58    Status422(models::ErrorResponse),
59    Status424(models::ErrorResponse),
60    Status500(models::ErrorResponse),
61    UnknownValue(serde_json::Value),
62}
63
64/// struct for typed errors of method [`create_balance_order`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum CreateBalanceOrderError {
68    Status401(models::ErrorResponse),
69    Status403(models::ErrorResponse),
70    Status422(models::ErrorResponse),
71    Status500(models::ErrorResponse),
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`delete_balance_definition`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum DeleteBalanceDefinitionError {
79    Status401(models::ErrorResponse),
80    Status403(models::ErrorResponse),
81    Status404(models::ErrorResponse),
82    Status422(models::ErrorResponse),
83    Status500(models::ErrorResponse),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`delete_balance_limit`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum DeleteBalanceLimitError {
91    Status401(models::ErrorResponse),
92    Status403(models::ErrorResponse),
93    Status404(models::ErrorResponse),
94    Status422(models::ErrorResponse),
95    Status500(models::ErrorResponse),
96    UnknownValue(serde_json::Value),
97}
98
99/// struct for typed errors of method [`get_balance_definition`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum GetBalanceDefinitionError {
103    Status401(models::ErrorResponse),
104    Status403(models::ErrorResponse),
105    Status404(models::ErrorResponse),
106    Status422(models::ErrorResponse),
107    Status500(models::ErrorResponse),
108    UnknownValue(serde_json::Value),
109}
110
111/// struct for typed errors of method [`get_balance_definition_list`]
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum GetBalanceDefinitionListError {
115    Status401(models::ErrorResponse),
116    Status403(models::ErrorResponse),
117    Status422(models::ErrorResponse),
118    Status500(models::ErrorResponse),
119    UnknownValue(serde_json::Value),
120}
121
122/// struct for typed errors of method [`get_balance_limit`]
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum GetBalanceLimitError {
126    Status401(models::ErrorResponse),
127    Status403(models::ErrorResponse),
128    Status404(models::ErrorResponse),
129    Status422(models::ErrorResponse),
130    Status500(models::ErrorResponse),
131    UnknownValue(serde_json::Value),
132}
133
134/// struct for typed errors of method [`get_contact_balances`]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum GetContactBalancesError {
138    Status401(models::ErrorResponse),
139    Status403(models::ErrorResponse),
140    Status404(models::ErrorResponse),
141    Status422(models::ErrorResponse),
142    Status500(models::ErrorResponse),
143    UnknownValue(serde_json::Value),
144}
145
146/// struct for typed errors of method [`get_subscription_balances`]
147#[derive(Debug, Clone, Serialize, Deserialize)]
148#[serde(untagged)]
149pub enum GetSubscriptionBalancesError {
150    Status401(models::ErrorResponse),
151    Status403(models::ErrorResponse),
152    Status404(models::ErrorResponse),
153    Status422(models::ErrorResponse),
154    Status500(models::ErrorResponse),
155    UnknownValue(serde_json::Value),
156}
157
158/// struct for typed errors of method [`loyalty_balance_programs_pid_active_balance_get`]
159#[derive(Debug, Clone, Serialize, Deserialize)]
160#[serde(untagged)]
161pub enum LoyaltyBalanceProgramsPidActiveBalanceGetError {
162    Status401(models::ErrorResponse),
163    Status403(models::ErrorResponse),
164    Status404(models::ErrorResponse),
165    Status422(models::ErrorResponse),
166    Status500(models::ErrorResponse),
167    UnknownValue(serde_json::Value),
168}
169
170/// struct for typed errors of method [`loyalty_balance_programs_pid_balance_definitions_post`]
171#[derive(Debug, Clone, Serialize, Deserialize)]
172#[serde(untagged)]
173pub enum LoyaltyBalanceProgramsPidBalanceDefinitionsPostError {
174    Status401(models::ErrorResponse),
175    Status403(models::ErrorResponse),
176    Status404(models::ErrorResponse),
177    Status422(models::ErrorResponse),
178    Status500(models::ErrorResponse),
179    UnknownValue(serde_json::Value),
180}
181
182/// struct for typed errors of method [`loyalty_balance_programs_pid_subscriptions_cid_balances_post`]
183#[derive(Debug, Clone, Serialize, Deserialize)]
184#[serde(untagged)]
185pub enum LoyaltyBalanceProgramsPidSubscriptionsCidBalancesPostError {
186    Status401(models::ErrorResponse),
187    Status403(models::ErrorResponse),
188    Status404(models::ErrorResponse),
189    Status422(models::ErrorResponse),
190    Status500(models::ErrorResponse),
191    UnknownValue(serde_json::Value),
192}
193
194/// struct for typed errors of method [`loyalty_balance_programs_pid_transaction_history_get`]
195#[derive(Debug, Clone, Serialize, Deserialize)]
196#[serde(untagged)]
197pub enum LoyaltyBalanceProgramsPidTransactionHistoryGetError {
198    Status401(models::ErrorResponse),
199    Status403(models::ErrorResponse),
200    Status404(models::ErrorResponse),
201    Status422(models::ErrorResponse),
202    Status500(models::ErrorResponse),
203    UnknownValue(serde_json::Value),
204}
205
206/// struct for typed errors of method [`update_balance_definition`]
207#[derive(Debug, Clone, Serialize, Deserialize)]
208#[serde(untagged)]
209pub enum UpdateBalanceDefinitionError {
210    Status401(models::ErrorResponse),
211    Status403(models::ErrorResponse),
212    Status404(models::ErrorResponse),
213    Status422(models::ErrorResponse),
214    Status424(models::ErrorResponse),
215    Status500(models::ErrorResponse),
216    UnknownValue(serde_json::Value),
217}
218
219/// struct for typed errors of method [`update_balance_limit`]
220#[derive(Debug, Clone, Serialize, Deserialize)]
221#[serde(untagged)]
222pub enum UpdateBalanceLimitError {
223    Status401(models::ErrorResponse),
224    Status403(models::ErrorResponse),
225    Status404(models::ErrorResponse),
226    Status422(models::ErrorResponse),
227    Status500(models::ErrorResponse),
228    UnknownValue(serde_json::Value),
229}
230
231/// Creates new transaction and returns information
232pub async fn begin_transaction(
233    configuration: &configuration::Configuration,
234    pid: &str,
235    create_transaction_payload: models::CreateTransactionPayload,
236) -> Result<models::Transaction, Error<BeginTransactionError>> {
237    // add a prefix to parameters to efficiently prevent name collisions
238    let p_pid = pid;
239    let p_create_transaction_payload = create_transaction_payload;
240
241    let uri_str = format!(
242        "{}/loyalty/balance/programs/{pid}/transactions",
243        configuration.base_path,
244        pid = crate::apis::urlencode(p_pid)
245    );
246    let mut req_builder = configuration
247        .client
248        .request(reqwest::Method::POST, &uri_str);
249
250    if let Some(ref user_agent) = configuration.user_agent {
251        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
252    }
253    if let Some(ref apikey) = configuration.api_key {
254        let key = apikey.key.clone();
255        let value = match apikey.prefix {
256            Some(ref prefix) => format!("{} {}", prefix, key),
257            None => key,
258        };
259        req_builder = req_builder.header("api-key", value);
260    };
261    req_builder = req_builder.json(&p_create_transaction_payload);
262
263    let req = req_builder.build()?;
264    let resp = configuration.client.execute(req).await?;
265
266    let status = resp.status();
267    let content_type = resp
268        .headers()
269        .get("content-type")
270        .and_then(|v| v.to_str().ok())
271        .unwrap_or("application/octet-stream");
272    let content_type = super::ContentType::from(content_type);
273
274    if !status.is_client_error() && !status.is_server_error() {
275        let content = resp.text().await?;
276        match content_type {
277            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
278            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Transaction`"))),
279            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Transaction`")))),
280        }
281    } else {
282        let content = resp.text().await?;
283        let entity: Option<BeginTransactionError> = serde_json::from_str(&content).ok();
284        Err(Error::ResponseError(ResponseContent {
285            status,
286            content,
287            entity,
288        }))
289    }
290}
291
292/// Cancels transaction
293pub async fn cancel_transaction(
294    configuration: &configuration::Configuration,
295    pid: &str,
296    tid: &str,
297) -> Result<models::Transaction, Error<CancelTransactionError>> {
298    // add a prefix to parameters to efficiently prevent name collisions
299    let p_pid = pid;
300    let p_tid = tid;
301
302    let uri_str = format!(
303        "{}/loyalty/balance/programs/{pid}/transactions/{tid}/cancel",
304        configuration.base_path,
305        pid = crate::apis::urlencode(p_pid),
306        tid = crate::apis::urlencode(p_tid)
307    );
308    let mut req_builder = configuration
309        .client
310        .request(reqwest::Method::POST, &uri_str);
311
312    if let Some(ref user_agent) = configuration.user_agent {
313        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
314    }
315    if let Some(ref apikey) = configuration.api_key {
316        let key = apikey.key.clone();
317        let value = match apikey.prefix {
318            Some(ref prefix) => format!("{} {}", prefix, key),
319            None => key,
320        };
321        req_builder = req_builder.header("api-key", value);
322    };
323
324    let req = req_builder.build()?;
325    let resp = configuration.client.execute(req).await?;
326
327    let status = resp.status();
328    let content_type = resp
329        .headers()
330        .get("content-type")
331        .and_then(|v| v.to_str().ok())
332        .unwrap_or("application/octet-stream");
333    let content_type = super::ContentType::from(content_type);
334
335    if !status.is_client_error() && !status.is_server_error() {
336        let content = resp.text().await?;
337        match content_type {
338            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
339            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Transaction`"))),
340            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Transaction`")))),
341        }
342    } else {
343        let content = resp.text().await?;
344        let entity: Option<CancelTransactionError> = serde_json::from_str(&content).ok();
345        Err(Error::ResponseError(ResponseContent {
346            status,
347            content,
348            entity,
349        }))
350    }
351}
352
353/// Completes transaction
354pub async fn complete_transaction(
355    configuration: &configuration::Configuration,
356    pid: &str,
357    tid: &str,
358) -> Result<models::Transaction, Error<CompleteTransactionError>> {
359    // add a prefix to parameters to efficiently prevent name collisions
360    let p_pid = pid;
361    let p_tid = tid;
362
363    let uri_str = format!(
364        "{}/loyalty/balance/programs/{pid}/transactions/{tid}/complete",
365        configuration.base_path,
366        pid = crate::apis::urlencode(p_pid),
367        tid = crate::apis::urlencode(p_tid)
368    );
369    let mut req_builder = configuration
370        .client
371        .request(reqwest::Method::POST, &uri_str);
372
373    if let Some(ref user_agent) = configuration.user_agent {
374        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
375    }
376    if let Some(ref apikey) = configuration.api_key {
377        let key = apikey.key.clone();
378        let value = match apikey.prefix {
379            Some(ref prefix) => format!("{} {}", prefix, key),
380            None => key,
381        };
382        req_builder = req_builder.header("api-key", value);
383    };
384
385    let req = req_builder.build()?;
386    let resp = configuration.client.execute(req).await?;
387
388    let status = resp.status();
389    let content_type = resp
390        .headers()
391        .get("content-type")
392        .and_then(|v| v.to_str().ok())
393        .unwrap_or("application/octet-stream");
394    let content_type = super::ContentType::from(content_type);
395
396    if !status.is_client_error() && !status.is_server_error() {
397        let content = resp.text().await?;
398        match content_type {
399            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
400            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Transaction`"))),
401            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Transaction`")))),
402        }
403    } else {
404        let content = resp.text().await?;
405        let entity: Option<CompleteTransactionError> = serde_json::from_str(&content).ok();
406        Err(Error::ResponseError(ResponseContent {
407            status,
408            content,
409            entity,
410        }))
411    }
412}
413
414/// Creates balance limit and sends the created UUID along with the data
415pub async fn create_balance_limit(
416    configuration: &configuration::Configuration,
417    pid: &str,
418    bdid: &str,
419    create_balance_limit_payload: models::CreateBalanceLimitPayload,
420) -> Result<models::BalanceLimit, Error<CreateBalanceLimitError>> {
421    // add a prefix to parameters to efficiently prevent name collisions
422    let p_pid = pid;
423    let p_bdid = bdid;
424    let p_create_balance_limit_payload = create_balance_limit_payload;
425
426    let uri_str = format!(
427        "{}/loyalty/balance/programs/{pid}/balance-definitions/{bdid}/limits",
428        configuration.base_path,
429        pid = crate::apis::urlencode(p_pid),
430        bdid = crate::apis::urlencode(p_bdid)
431    );
432    let mut req_builder = configuration
433        .client
434        .request(reqwest::Method::POST, &uri_str);
435
436    if let Some(ref user_agent) = configuration.user_agent {
437        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
438    }
439    if let Some(ref apikey) = configuration.api_key {
440        let key = apikey.key.clone();
441        let value = match apikey.prefix {
442            Some(ref prefix) => format!("{} {}", prefix, key),
443            None => key,
444        };
445        req_builder = req_builder.header("api-key", value);
446    };
447    req_builder = req_builder.json(&p_create_balance_limit_payload);
448
449    let req = req_builder.build()?;
450    let resp = configuration.client.execute(req).await?;
451
452    let status = resp.status();
453    let content_type = resp
454        .headers()
455        .get("content-type")
456        .and_then(|v| v.to_str().ok())
457        .unwrap_or("application/octet-stream");
458    let content_type = super::ContentType::from(content_type);
459
460    if !status.is_client_error() && !status.is_server_error() {
461        let content = resp.text().await?;
462        match content_type {
463            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
464            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceLimit`"))),
465            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceLimit`")))),
466        }
467    } else {
468        let content = resp.text().await?;
469        let entity: Option<CreateBalanceLimitError> = serde_json::from_str(&content).ok();
470        Err(Error::ResponseError(ResponseContent {
471            status,
472            content,
473            entity,
474        }))
475    }
476}
477
478/// Returns created order
479pub async fn create_balance_order(
480    configuration: &configuration::Configuration,
481    pid: &str,
482    create_order_payload: models::CreateOrderPayload,
483) -> Result<models::BalanceOrder, Error<CreateBalanceOrderError>> {
484    // add a prefix to parameters to efficiently prevent name collisions
485    let p_pid = pid;
486    let p_create_order_payload = create_order_payload;
487
488    let uri_str = format!(
489        "{}/loyalty/balance/programs/{pid}/create-order",
490        configuration.base_path,
491        pid = crate::apis::urlencode(p_pid)
492    );
493    let mut req_builder = configuration
494        .client
495        .request(reqwest::Method::POST, &uri_str);
496
497    if let Some(ref user_agent) = configuration.user_agent {
498        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
499    }
500    if let Some(ref apikey) = configuration.api_key {
501        let key = apikey.key.clone();
502        let value = match apikey.prefix {
503            Some(ref prefix) => format!("{} {}", prefix, key),
504            None => key,
505        };
506        req_builder = req_builder.header("api-key", value);
507    };
508    req_builder = req_builder.json(&p_create_order_payload);
509
510    let req = req_builder.build()?;
511    let resp = configuration.client.execute(req).await?;
512
513    let status = resp.status();
514    let content_type = resp
515        .headers()
516        .get("content-type")
517        .and_then(|v| v.to_str().ok())
518        .unwrap_or("application/octet-stream");
519    let content_type = super::ContentType::from(content_type);
520
521    if !status.is_client_error() && !status.is_server_error() {
522        let content = resp.text().await?;
523        match content_type {
524            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
525            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceOrder`"))),
526            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceOrder`")))),
527        }
528    } else {
529        let content = resp.text().await?;
530        let entity: Option<CreateBalanceOrderError> = serde_json::from_str(&content).ok();
531        Err(Error::ResponseError(ResponseContent {
532            status,
533            content,
534            entity,
535        }))
536    }
537}
538
539/// Delete Balance definition
540pub async fn delete_balance_definition(
541    configuration: &configuration::Configuration,
542    pid: &str,
543    bdid: &str,
544) -> Result<(), Error<DeleteBalanceDefinitionError>> {
545    // add a prefix to parameters to efficiently prevent name collisions
546    let p_pid = pid;
547    let p_bdid = bdid;
548
549    let uri_str = format!(
550        "{}/loyalty/balance/programs/{pid}/balance-definitions/{bdid}",
551        configuration.base_path,
552        pid = crate::apis::urlencode(p_pid),
553        bdid = crate::apis::urlencode(p_bdid)
554    );
555    let mut req_builder = configuration
556        .client
557        .request(reqwest::Method::DELETE, &uri_str);
558
559    if let Some(ref user_agent) = configuration.user_agent {
560        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
561    }
562    if let Some(ref apikey) = configuration.api_key {
563        let key = apikey.key.clone();
564        let value = match apikey.prefix {
565            Some(ref prefix) => format!("{} {}", prefix, key),
566            None => key,
567        };
568        req_builder = req_builder.header("api-key", value);
569    };
570
571    let req = req_builder.build()?;
572    let resp = configuration.client.execute(req).await?;
573
574    let status = resp.status();
575
576    if !status.is_client_error() && !status.is_server_error() {
577        Ok(())
578    } else {
579        let content = resp.text().await?;
580        let entity: Option<DeleteBalanceDefinitionError> = serde_json::from_str(&content).ok();
581        Err(Error::ResponseError(ResponseContent {
582            status,
583            content,
584            entity,
585        }))
586    }
587}
588
589/// Delete balance limit
590pub async fn delete_balance_limit(
591    configuration: &configuration::Configuration,
592    pid: &str,
593    bdid: &str,
594    blid: &str,
595) -> Result<(), Error<DeleteBalanceLimitError>> {
596    // add a prefix to parameters to efficiently prevent name collisions
597    let p_pid = pid;
598    let p_bdid = bdid;
599    let p_blid = blid;
600
601    let uri_str = format!(
602        "{}/loyalty/balance/programs/{pid}/balance-definitions/{bdid}/limits/{blid}",
603        configuration.base_path,
604        pid = crate::apis::urlencode(p_pid),
605        bdid = crate::apis::urlencode(p_bdid),
606        blid = crate::apis::urlencode(p_blid)
607    );
608    let mut req_builder = configuration
609        .client
610        .request(reqwest::Method::DELETE, &uri_str);
611
612    if let Some(ref user_agent) = configuration.user_agent {
613        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
614    }
615    if let Some(ref apikey) = configuration.api_key {
616        let key = apikey.key.clone();
617        let value = match apikey.prefix {
618            Some(ref prefix) => format!("{} {}", prefix, key),
619            None => key,
620        };
621        req_builder = req_builder.header("api-key", value);
622    };
623
624    let req = req_builder.build()?;
625    let resp = configuration.client.execute(req).await?;
626
627    let status = resp.status();
628
629    if !status.is_client_error() && !status.is_server_error() {
630        Ok(())
631    } else {
632        let content = resp.text().await?;
633        let entity: Option<DeleteBalanceLimitError> = serde_json::from_str(&content).ok();
634        Err(Error::ResponseError(ResponseContent {
635            status,
636            content,
637            entity,
638        }))
639    }
640}
641
642/// Returns balance definition
643pub async fn get_balance_definition(
644    configuration: &configuration::Configuration,
645    pid: &str,
646    bdid: &str,
647    version: Option<&str>,
648) -> Result<models::BalanceDefinition, Error<GetBalanceDefinitionError>> {
649    // add a prefix to parameters to efficiently prevent name collisions
650    let p_pid = pid;
651    let p_bdid = bdid;
652    let p_version = version;
653
654    let uri_str = format!(
655        "{}/loyalty/balance/programs/{pid}/balance-definitions/{bdid}",
656        configuration.base_path,
657        pid = crate::apis::urlencode(p_pid),
658        bdid = crate::apis::urlencode(p_bdid)
659    );
660    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
661
662    if let Some(ref param_value) = p_version {
663        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
664    }
665    if let Some(ref user_agent) = configuration.user_agent {
666        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
667    }
668    if let Some(ref apikey) = configuration.api_key {
669        let key = apikey.key.clone();
670        let value = match apikey.prefix {
671            Some(ref prefix) => format!("{} {}", prefix, key),
672            None => key,
673        };
674        req_builder = req_builder.header("api-key", value);
675    };
676
677    let req = req_builder.build()?;
678    let resp = configuration.client.execute(req).await?;
679
680    let status = resp.status();
681    let content_type = resp
682        .headers()
683        .get("content-type")
684        .and_then(|v| v.to_str().ok())
685        .unwrap_or("application/octet-stream");
686    let content_type = super::ContentType::from(content_type);
687
688    if !status.is_client_error() && !status.is_server_error() {
689        let content = resp.text().await?;
690        match content_type {
691            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
692            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceDefinition`"))),
693            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceDefinition`")))),
694        }
695    } else {
696        let content = resp.text().await?;
697        let entity: Option<GetBalanceDefinitionError> = serde_json::from_str(&content).ok();
698        Err(Error::ResponseError(ResponseContent {
699            status,
700            content,
701            entity,
702        }))
703    }
704}
705
706/// Returns balance definition page
707pub async fn get_balance_definition_list(
708    configuration: &configuration::Configuration,
709    pid: &str,
710    limit: Option<i32>,
711    offset: Option<i32>,
712    sort_field: Option<&str>,
713    sort: Option<&str>,
714    version: Option<&str>,
715) -> Result<models::BalanceDefinitionPage, Error<GetBalanceDefinitionListError>> {
716    // add a prefix to parameters to efficiently prevent name collisions
717    let p_pid = pid;
718    let p_limit = limit;
719    let p_offset = offset;
720    let p_sort_field = sort_field;
721    let p_sort = sort;
722    let p_version = version;
723
724    let uri_str = format!(
725        "{}/loyalty/balance/programs/{pid}/balance-definitions",
726        configuration.base_path,
727        pid = crate::apis::urlencode(p_pid)
728    );
729    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
730
731    if let Some(ref param_value) = p_limit {
732        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
733    }
734    if let Some(ref param_value) = p_offset {
735        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
736    }
737    if let Some(ref param_value) = p_sort_field {
738        req_builder = req_builder.query(&[("sortField", &param_value.to_string())]);
739    }
740    if let Some(ref param_value) = p_sort {
741        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
742    }
743    if let Some(ref param_value) = p_version {
744        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
745    }
746    if let Some(ref user_agent) = configuration.user_agent {
747        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
748    }
749    if let Some(ref apikey) = configuration.api_key {
750        let key = apikey.key.clone();
751        let value = match apikey.prefix {
752            Some(ref prefix) => format!("{} {}", prefix, key),
753            None => key,
754        };
755        req_builder = req_builder.header("api-key", value);
756    };
757
758    let req = req_builder.build()?;
759    let resp = configuration.client.execute(req).await?;
760
761    let status = resp.status();
762    let content_type = resp
763        .headers()
764        .get("content-type")
765        .and_then(|v| v.to_str().ok())
766        .unwrap_or("application/octet-stream");
767    let content_type = super::ContentType::from(content_type);
768
769    if !status.is_client_error() && !status.is_server_error() {
770        let content = resp.text().await?;
771        match content_type {
772            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
773            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceDefinitionPage`"))),
774            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceDefinitionPage`")))),
775        }
776    } else {
777        let content = resp.text().await?;
778        let entity: Option<GetBalanceDefinitionListError> = serde_json::from_str(&content).ok();
779        Err(Error::ResponseError(ResponseContent {
780            status,
781            content,
782            entity,
783        }))
784    }
785}
786
787/// Fetches balance limits and send the created UUID along with the data
788pub async fn get_balance_limit(
789    configuration: &configuration::Configuration,
790    pid: &str,
791    bdid: &str,
792    blid: &str,
793    version: Option<&str>,
794) -> Result<models::BalanceLimit, Error<GetBalanceLimitError>> {
795    // add a prefix to parameters to efficiently prevent name collisions
796    let p_pid = pid;
797    let p_bdid = bdid;
798    let p_blid = blid;
799    let p_version = version;
800
801    let uri_str = format!(
802        "{}/loyalty/balance/programs/{pid}/balance-definitions/{bdid}/limits/{blid}",
803        configuration.base_path,
804        pid = crate::apis::urlencode(p_pid),
805        bdid = crate::apis::urlencode(p_bdid),
806        blid = crate::apis::urlencode(p_blid)
807    );
808    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
809
810    if let Some(ref param_value) = p_version {
811        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
812    }
813    if let Some(ref user_agent) = configuration.user_agent {
814        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
815    }
816    if let Some(ref apikey) = configuration.api_key {
817        let key = apikey.key.clone();
818        let value = match apikey.prefix {
819            Some(ref prefix) => format!("{} {}", prefix, key),
820            None => key,
821        };
822        req_builder = req_builder.header("api-key", value);
823    };
824
825    let req = req_builder.build()?;
826    let resp = configuration.client.execute(req).await?;
827
828    let status = resp.status();
829    let content_type = resp
830        .headers()
831        .get("content-type")
832        .and_then(|v| v.to_str().ok())
833        .unwrap_or("application/octet-stream");
834    let content_type = super::ContentType::from(content_type);
835
836    if !status.is_client_error() && !status.is_server_error() {
837        let content = resp.text().await?;
838        match content_type {
839            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
840            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceLimit`"))),
841            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceLimit`")))),
842        }
843    } else {
844        let content = resp.text().await?;
845        let entity: Option<GetBalanceLimitError> = serde_json::from_str(&content).ok();
846        Err(Error::ResponseError(ResponseContent {
847            status,
848            content,
849            entity,
850        }))
851    }
852}
853
854/// Returns balance list
855pub async fn get_contact_balances(
856    configuration: &configuration::Configuration,
857    pid: &str,
858) -> Result<models::ContactBalancesResp, Error<GetContactBalancesError>> {
859    // add a prefix to parameters to efficiently prevent name collisions
860    let p_pid = pid;
861
862    let uri_str = format!(
863        "{}/loyalty/balance/programs/{pid}/contact-balances",
864        configuration.base_path,
865        pid = crate::apis::urlencode(p_pid)
866    );
867    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
868
869    if let Some(ref user_agent) = configuration.user_agent {
870        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
871    }
872    if let Some(ref apikey) = configuration.api_key {
873        let key = apikey.key.clone();
874        let value = match apikey.prefix {
875            Some(ref prefix) => format!("{} {}", prefix, key),
876            None => key,
877        };
878        req_builder = req_builder.header("api-key", value);
879    };
880
881    let req = req_builder.build()?;
882    let resp = configuration.client.execute(req).await?;
883
884    let status = resp.status();
885    let content_type = resp
886        .headers()
887        .get("content-type")
888        .and_then(|v| v.to_str().ok())
889        .unwrap_or("application/octet-stream");
890    let content_type = super::ContentType::from(content_type);
891
892    if !status.is_client_error() && !status.is_server_error() {
893        let content = resp.text().await?;
894        match content_type {
895            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
896            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ContactBalancesResp`"))),
897            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ContactBalancesResp`")))),
898        }
899    } else {
900        let content = resp.text().await?;
901        let entity: Option<GetContactBalancesError> = serde_json::from_str(&content).ok();
902        Err(Error::ResponseError(ResponseContent {
903            status,
904            content,
905            entity,
906        }))
907    }
908}
909
910/// Returns subscription balances
911pub async fn get_subscription_balances(
912    configuration: &configuration::Configuration,
913    cid: &str,
914    pid: &str,
915) -> Result<models::ModelSubscriptionBalanceResp, Error<GetSubscriptionBalancesError>> {
916    // add a prefix to parameters to efficiently prevent name collisions
917    let p_cid = cid;
918    let p_pid = pid;
919
920    let uri_str = format!(
921        "{}/loyalty/balance/programs/{pid}/subscriptions/{cid}/balances",
922        configuration.base_path,
923        cid = crate::apis::urlencode(p_cid),
924        pid = crate::apis::urlencode(p_pid)
925    );
926    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
927
928    if let Some(ref user_agent) = configuration.user_agent {
929        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
930    }
931    if let Some(ref apikey) = configuration.api_key {
932        let key = apikey.key.clone();
933        let value = match apikey.prefix {
934            Some(ref prefix) => format!("{} {}", prefix, key),
935            None => key,
936        };
937        req_builder = req_builder.header("api-key", value);
938    };
939
940    let req = req_builder.build()?;
941    let resp = configuration.client.execute(req).await?;
942
943    let status = resp.status();
944    let content_type = resp
945        .headers()
946        .get("content-type")
947        .and_then(|v| v.to_str().ok())
948        .unwrap_or("application/octet-stream");
949    let content_type = super::ContentType::from(content_type);
950
951    if !status.is_client_error() && !status.is_server_error() {
952        let content = resp.text().await?;
953        match content_type {
954            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
955            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ModelSubscriptionBalanceResp`"))),
956            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ModelSubscriptionBalanceResp`")))),
957        }
958    } else {
959        let content = resp.text().await?;
960        let entity: Option<GetSubscriptionBalancesError> = serde_json::from_str(&content).ok();
961        Err(Error::ResponseError(ResponseContent {
962            status,
963            content,
964            entity,
965        }))
966    }
967}
968
969/// Returns Active Balances
970pub async fn loyalty_balance_programs_pid_active_balance_get(
971    configuration: &configuration::Configuration,
972    pid: &str,
973    contact_id: i32,
974    balance_definition_id: &str,
975    limit: Option<i32>,
976    offset: Option<i32>,
977    sort_field: Option<&str>,
978    sort: Option<&str>,
979) -> Result<models::BalanceLimit, Error<LoyaltyBalanceProgramsPidActiveBalanceGetError>> {
980    // add a prefix to parameters to efficiently prevent name collisions
981    let p_pid = pid;
982    let p_contact_id = contact_id;
983    let p_balance_definition_id = balance_definition_id;
984    let p_limit = limit;
985    let p_offset = offset;
986    let p_sort_field = sort_field;
987    let p_sort = sort;
988
989    let uri_str = format!(
990        "{}/loyalty/balance/programs/{pid}/active-balance",
991        configuration.base_path,
992        pid = crate::apis::urlencode(p_pid)
993    );
994    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
995
996    if let Some(ref param_value) = p_limit {
997        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
998    }
999    if let Some(ref param_value) = p_offset {
1000        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
1001    }
1002    if let Some(ref param_value) = p_sort_field {
1003        req_builder = req_builder.query(&[("sort_field", &param_value.to_string())]);
1004    }
1005    if let Some(ref param_value) = p_sort {
1006        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
1007    }
1008    req_builder = req_builder.query(&[("contact_id", &p_contact_id.to_string())]);
1009    req_builder = req_builder.query(&[(
1010        "balance_definition_id",
1011        &p_balance_definition_id.to_string(),
1012    )]);
1013    if let Some(ref user_agent) = configuration.user_agent {
1014        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1015    }
1016    if let Some(ref apikey) = configuration.api_key {
1017        let key = apikey.key.clone();
1018        let value = match apikey.prefix {
1019            Some(ref prefix) => format!("{} {}", prefix, key),
1020            None => key,
1021        };
1022        req_builder = req_builder.header("api-key", value);
1023    };
1024
1025    let req = req_builder.build()?;
1026    let resp = configuration.client.execute(req).await?;
1027
1028    let status = resp.status();
1029    let content_type = resp
1030        .headers()
1031        .get("content-type")
1032        .and_then(|v| v.to_str().ok())
1033        .unwrap_or("application/octet-stream");
1034    let content_type = super::ContentType::from(content_type);
1035
1036    if !status.is_client_error() && !status.is_server_error() {
1037        let content = resp.text().await?;
1038        match content_type {
1039            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1040            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceLimit`"))),
1041            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceLimit`")))),
1042        }
1043    } else {
1044        let content = resp.text().await?;
1045        let entity: Option<LoyaltyBalanceProgramsPidActiveBalanceGetError> =
1046            serde_json::from_str(&content).ok();
1047        Err(Error::ResponseError(ResponseContent {
1048            status,
1049            content,
1050            entity,
1051        }))
1052    }
1053}
1054
1055/// Creates balance definition and returns information
1056pub async fn loyalty_balance_programs_pid_balance_definitions_post(
1057    configuration: &configuration::Configuration,
1058    pid: &str,
1059    create_balance_definition_payload: models::CreateBalanceDefinitionPayload,
1060) -> Result<models::BalanceDefinition, Error<LoyaltyBalanceProgramsPidBalanceDefinitionsPostError>>
1061{
1062    // add a prefix to parameters to efficiently prevent name collisions
1063    let p_pid = pid;
1064    let p_create_balance_definition_payload = create_balance_definition_payload;
1065
1066    let uri_str = format!(
1067        "{}/loyalty/balance/programs/{pid}/balance-definitions",
1068        configuration.base_path,
1069        pid = crate::apis::urlencode(p_pid)
1070    );
1071    let mut req_builder = configuration
1072        .client
1073        .request(reqwest::Method::POST, &uri_str);
1074
1075    if let Some(ref user_agent) = configuration.user_agent {
1076        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1077    }
1078    if let Some(ref apikey) = configuration.api_key {
1079        let key = apikey.key.clone();
1080        let value = match apikey.prefix {
1081            Some(ref prefix) => format!("{} {}", prefix, key),
1082            None => key,
1083        };
1084        req_builder = req_builder.header("api-key", value);
1085    };
1086    req_builder = req_builder.json(&p_create_balance_definition_payload);
1087
1088    let req = req_builder.build()?;
1089    let resp = configuration.client.execute(req).await?;
1090
1091    let status = resp.status();
1092    let content_type = resp
1093        .headers()
1094        .get("content-type")
1095        .and_then(|v| v.to_str().ok())
1096        .unwrap_or("application/octet-stream");
1097    let content_type = super::ContentType::from(content_type);
1098
1099    if !status.is_client_error() && !status.is_server_error() {
1100        let content = resp.text().await?;
1101        match content_type {
1102            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1103            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceDefinition`"))),
1104            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceDefinition`")))),
1105        }
1106    } else {
1107        let content = resp.text().await?;
1108        let entity: Option<LoyaltyBalanceProgramsPidBalanceDefinitionsPostError> =
1109            serde_json::from_str(&content).ok();
1110        Err(Error::ResponseError(ResponseContent {
1111            status,
1112            content,
1113            entity,
1114        }))
1115    }
1116}
1117
1118/// Creates a balance for a contact
1119pub async fn loyalty_balance_programs_pid_subscriptions_cid_balances_post(
1120    configuration: &configuration::Configuration,
1121    pid: &str,
1122    cid: &str,
1123    create_balance_payload: models::CreateBalancePayload,
1124) -> Result<models::Balance, Error<LoyaltyBalanceProgramsPidSubscriptionsCidBalancesPostError>> {
1125    // add a prefix to parameters to efficiently prevent name collisions
1126    let p_pid = pid;
1127    let p_cid = cid;
1128    let p_create_balance_payload = create_balance_payload;
1129
1130    let uri_str = format!(
1131        "{}/loyalty/balance/programs/{pid}/subscriptions/{cid}/balances",
1132        configuration.base_path,
1133        pid = crate::apis::urlencode(p_pid),
1134        cid = crate::apis::urlencode(p_cid)
1135    );
1136    let mut req_builder = configuration
1137        .client
1138        .request(reqwest::Method::POST, &uri_str);
1139
1140    if let Some(ref user_agent) = configuration.user_agent {
1141        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1142    }
1143    if let Some(ref apikey) = configuration.api_key {
1144        let key = apikey.key.clone();
1145        let value = match apikey.prefix {
1146            Some(ref prefix) => format!("{} {}", prefix, key),
1147            None => key,
1148        };
1149        req_builder = req_builder.header("api-key", value);
1150    };
1151    req_builder = req_builder.json(&p_create_balance_payload);
1152
1153    let req = req_builder.build()?;
1154    let resp = configuration.client.execute(req).await?;
1155
1156    let status = resp.status();
1157    let content_type = resp
1158        .headers()
1159        .get("content-type")
1160        .and_then(|v| v.to_str().ok())
1161        .unwrap_or("application/octet-stream");
1162    let content_type = super::ContentType::from(content_type);
1163
1164    if !status.is_client_error() && !status.is_server_error() {
1165        let content = resp.text().await?;
1166        match content_type {
1167            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1168            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Balance`"))),
1169            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Balance`")))),
1170        }
1171    } else {
1172        let content = resp.text().await?;
1173        let entity: Option<LoyaltyBalanceProgramsPidSubscriptionsCidBalancesPostError> =
1174            serde_json::from_str(&content).ok();
1175        Err(Error::ResponseError(ResponseContent {
1176            status,
1177            content,
1178            entity,
1179        }))
1180    }
1181}
1182
1183/// Returns transaction history
1184pub async fn loyalty_balance_programs_pid_transaction_history_get(
1185    configuration: &configuration::Configuration,
1186    pid: &str,
1187    contact_id: i32,
1188    balance_definition_id: &str,
1189    limit: Option<i32>,
1190    offset: Option<i32>,
1191    sort_field: Option<&str>,
1192    sort: Option<&str>,
1193    filters: Option<Vec<String>>,
1194) -> Result<
1195    models::TransactionHistoryResp,
1196    Error<LoyaltyBalanceProgramsPidTransactionHistoryGetError>,
1197> {
1198    // add a prefix to parameters to efficiently prevent name collisions
1199    let p_pid = pid;
1200    let p_contact_id = contact_id;
1201    let p_balance_definition_id = balance_definition_id;
1202    let p_limit = limit;
1203    let p_offset = offset;
1204    let p_sort_field = sort_field;
1205    let p_sort = sort;
1206    let p_filters = filters;
1207
1208    let uri_str = format!(
1209        "{}/loyalty/balance/programs/{pid}/transaction-history",
1210        configuration.base_path,
1211        pid = crate::apis::urlencode(p_pid)
1212    );
1213    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1214
1215    if let Some(ref param_value) = p_limit {
1216        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
1217    }
1218    if let Some(ref param_value) = p_offset {
1219        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
1220    }
1221    if let Some(ref param_value) = p_sort_field {
1222        req_builder = req_builder.query(&[("sort_field", &param_value.to_string())]);
1223    }
1224    if let Some(ref param_value) = p_sort {
1225        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
1226    }
1227    req_builder = req_builder.query(&[("contact_id", &p_contact_id.to_string())]);
1228    req_builder = req_builder.query(&[(
1229        "balance_definition_id",
1230        &p_balance_definition_id.to_string(),
1231    )]);
1232    if let Some(ref param_value) = p_filters {
1233        req_builder = match "multi" {
1234            "multi" => req_builder.query(
1235                &param_value
1236                    .iter()
1237                    .map(|p| ("filters".to_owned(), p.to_string()))
1238                    .collect::<Vec<(std::string::String, std::string::String)>>(),
1239            ),
1240            _ => req_builder.query(&[(
1241                "filters",
1242                &param_value
1243                    .iter()
1244                    .map(|p| p.to_string())
1245                    .collect::<Vec<String>>()
1246                    .join(",")
1247                    .to_string(),
1248            )]),
1249        };
1250    }
1251    if let Some(ref user_agent) = configuration.user_agent {
1252        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1253    }
1254    if let Some(ref apikey) = configuration.api_key {
1255        let key = apikey.key.clone();
1256        let value = match apikey.prefix {
1257            Some(ref prefix) => format!("{} {}", prefix, key),
1258            None => key,
1259        };
1260        req_builder = req_builder.header("api-key", value);
1261    };
1262
1263    let req = req_builder.build()?;
1264    let resp = configuration.client.execute(req).await?;
1265
1266    let status = resp.status();
1267    let content_type = resp
1268        .headers()
1269        .get("content-type")
1270        .and_then(|v| v.to_str().ok())
1271        .unwrap_or("application/octet-stream");
1272    let content_type = super::ContentType::from(content_type);
1273
1274    if !status.is_client_error() && !status.is_server_error() {
1275        let content = resp.text().await?;
1276        match content_type {
1277            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1278            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TransactionHistoryResp`"))),
1279            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TransactionHistoryResp`")))),
1280        }
1281    } else {
1282        let content = resp.text().await?;
1283        let entity: Option<LoyaltyBalanceProgramsPidTransactionHistoryGetError> =
1284            serde_json::from_str(&content).ok();
1285        Err(Error::ResponseError(ResponseContent {
1286            status,
1287            content,
1288            entity,
1289        }))
1290    }
1291}
1292
1293/// Updates Balance definition
1294pub async fn update_balance_definition(
1295    configuration: &configuration::Configuration,
1296    pid: &str,
1297    bdid: &str,
1298    update_balance_definition_payload: models::UpdateBalanceDefinitionPayload,
1299) -> Result<models::BalanceDefinition, Error<UpdateBalanceDefinitionError>> {
1300    // add a prefix to parameters to efficiently prevent name collisions
1301    let p_pid = pid;
1302    let p_bdid = bdid;
1303    let p_update_balance_definition_payload = update_balance_definition_payload;
1304
1305    let uri_str = format!(
1306        "{}/loyalty/balance/programs/{pid}/balance-definitions/{bdid}",
1307        configuration.base_path,
1308        pid = crate::apis::urlencode(p_pid),
1309        bdid = crate::apis::urlencode(p_bdid)
1310    );
1311    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1312
1313    if let Some(ref user_agent) = configuration.user_agent {
1314        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1315    }
1316    if let Some(ref apikey) = configuration.api_key {
1317        let key = apikey.key.clone();
1318        let value = match apikey.prefix {
1319            Some(ref prefix) => format!("{} {}", prefix, key),
1320            None => key,
1321        };
1322        req_builder = req_builder.header("api-key", value);
1323    };
1324    req_builder = req_builder.json(&p_update_balance_definition_payload);
1325
1326    let req = req_builder.build()?;
1327    let resp = configuration.client.execute(req).await?;
1328
1329    let status = resp.status();
1330    let content_type = resp
1331        .headers()
1332        .get("content-type")
1333        .and_then(|v| v.to_str().ok())
1334        .unwrap_or("application/octet-stream");
1335    let content_type = super::ContentType::from(content_type);
1336
1337    if !status.is_client_error() && !status.is_server_error() {
1338        let content = resp.text().await?;
1339        match content_type {
1340            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1341            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceDefinition`"))),
1342            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceDefinition`")))),
1343        }
1344    } else {
1345        let content = resp.text().await?;
1346        let entity: Option<UpdateBalanceDefinitionError> = serde_json::from_str(&content).ok();
1347        Err(Error::ResponseError(ResponseContent {
1348            status,
1349            content,
1350            entity,
1351        }))
1352    }
1353}
1354
1355/// Updates balance limit
1356pub async fn update_balance_limit(
1357    configuration: &configuration::Configuration,
1358    pid: &str,
1359    bdid: &str,
1360    blid: &str,
1361    update_balance_limit_payload: models::UpdateBalanceLimitPayload,
1362) -> Result<models::BalanceLimit, Error<UpdateBalanceLimitError>> {
1363    // add a prefix to parameters to efficiently prevent name collisions
1364    let p_pid = pid;
1365    let p_bdid = bdid;
1366    let p_blid = blid;
1367    let p_update_balance_limit_payload = update_balance_limit_payload;
1368
1369    let uri_str = format!(
1370        "{}/loyalty/balance/programs/{pid}/balance-definitions/{bdid}/limits/{blid}",
1371        configuration.base_path,
1372        pid = crate::apis::urlencode(p_pid),
1373        bdid = crate::apis::urlencode(p_bdid),
1374        blid = crate::apis::urlencode(p_blid)
1375    );
1376    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1377
1378    if let Some(ref user_agent) = configuration.user_agent {
1379        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1380    }
1381    if let Some(ref apikey) = configuration.api_key {
1382        let key = apikey.key.clone();
1383        let value = match apikey.prefix {
1384            Some(ref prefix) => format!("{} {}", prefix, key),
1385            None => key,
1386        };
1387        req_builder = req_builder.header("api-key", value);
1388    };
1389    req_builder = req_builder.json(&p_update_balance_limit_payload);
1390
1391    let req = req_builder.build()?;
1392    let resp = configuration.client.execute(req).await?;
1393
1394    let status = resp.status();
1395    let content_type = resp
1396        .headers()
1397        .get("content-type")
1398        .and_then(|v| v.to_str().ok())
1399        .unwrap_or("application/octet-stream");
1400    let content_type = super::ContentType::from(content_type);
1401
1402    if !status.is_client_error() && !status.is_server_error() {
1403        let content = resp.text().await?;
1404        match content_type {
1405            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1406            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BalanceLimit`"))),
1407            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BalanceLimit`")))),
1408        }
1409    } else {
1410        let content = resp.text().await?;
1411        let entity: Option<UpdateBalanceLimitError> = serde_json::from_str(&content).ok();
1412        Err(Error::ResponseError(ResponseContent {
1413            status,
1414            content,
1415            entity,
1416        }))
1417    }
1418}