qcs_api_client_openapi/apis/
account_api.rs

1// Copyright 2022 Rigetti Computing
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*
16 * Rigetti QCS API
17 *
18 * # Introduction  This is the documentation for the Rigetti QCS HTTP API.  You can find out more about Rigetti at [https://rigetti.com](https://rigetti.com), and also interact with QCS via the web at [https://qcs.rigetti.com](https://qcs.rigetti.com).  This API is documented in **OpenAPI format** and so is compatible with the dozens of language-specific client generators available [here](https://github.com/OpenAPITools/openapi-generator) and elsewhere on the web.  # Principles  This API follows REST design principles where appropriate, and otherwise an HTTP RPC paradigm. We adhere to the Google [API Improvement Proposals](https://google.aip.dev/general) where reasonable to provide a consistent, intuitive developer experience. HTTP response codes match their specifications, and error messages fit a common format.  # Authentication  All access to the QCS API requires OAuth2 authentication provided by Okta. You can request access [here](https://www.rigetti.com/get-quantum). Once you have a user account, you can download your access token from QCS [here](https://qcs.rigetti.com/auth/token).   That access token is valid for 24 hours after issuance. The value of `access_token` within the JSON file is the token used for authentication (don't use the entire JSON file).  Authenticate requests using the `Authorization` header and a `Bearer` prefix:  ``` curl --header \"Authorization: Bearer eyJraW...Iow\" ```  # Quantum Processor Access  Access to the quantum processors themselves is not yet provided directly by this HTTP API, but is instead performed over ZeroMQ/[rpcq](https://github.com/rigetti/rpcq). Until that changes, we suggest using [pyquil](https://github.com/rigetti/pyquil) to build and execute quantum programs via the Legacy API.  # Legacy API  Our legacy HTTP API remains accessible at https://forest-server.qcs.rigetti.com, and it shares a source of truth with this API's services. You can use either service with the same user account and means of authentication. We strongly recommend using the API documented here, as the legacy API is on the path to deprecation.
19 *
20 * The version of the OpenAPI document: 2020-07-31
21 * Contact: support@rigetti.com
22 * Generated by: https://openapi-generator.tech
23 */
24
25use super::{configuration, Error};
26use crate::apis::ResponseContent;
27use ::qcs_api_client_common::backoff::{
28    duration_from_io_error, duration_from_reqwest_error, duration_from_response, ExponentialBackoff,
29};
30#[cfg(feature = "tracing")]
31use qcs_api_client_common::configuration::TokenRefresher;
32use reqwest::StatusCode;
33use serde::{Deserialize, Serialize};
34
35/// struct for typed errors of method [`activate_user`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum ActivateUserError {
39    Status422(crate::models::Error),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`add_group_user`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum AddGroupUserError {
47    Status404(crate::models::Error),
48    Status422(crate::models::Error),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`dismiss_viewer_announcement`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum DismissViewerAnnouncementError {
56    Status401(crate::models::Error),
57    Status404(crate::models::Error),
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`get_group_balance`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum GetGroupBalanceError {
65    Status403(crate::models::Error),
66    Status404(crate::models::Error),
67    Status422(crate::models::Error),
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`get_group_billing_customer`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum GetGroupBillingCustomerError {
75    Status403(crate::models::Error),
76    Status404(crate::models::Error),
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`get_group_upcoming_billing_invoice`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum GetGroupUpcomingBillingInvoiceError {
84    Status403(crate::models::Error),
85    Status404(crate::models::Error),
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`get_user_balance`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum GetUserBalanceError {
93    Status403(crate::models::Error),
94    Status404(crate::models::Error),
95    Status422(crate::models::Error),
96    UnknownValue(serde_json::Value),
97}
98
99/// struct for typed errors of method [`get_user_billing_customer`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum GetUserBillingCustomerError {
103    Status403(crate::models::Error),
104    Status404(crate::models::Error),
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`get_user_event_billing_price`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum GetUserEventBillingPriceError {
112    Status403(crate::models::Error),
113    Status404(crate::models::Error),
114    Status422(crate::models::Error),
115    UnknownValue(serde_json::Value),
116}
117
118/// struct for typed errors of method [`get_user_upcoming_billing_invoice`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum GetUserUpcomingBillingInvoiceError {
122    Status403(crate::models::Error),
123    Status404(crate::models::Error),
124    UnknownValue(serde_json::Value),
125}
126
127/// struct for typed errors of method [`get_viewer_user_onboarding_completed`]
128#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum GetViewerUserOnboardingCompletedError {
131    Status401(crate::models::Error),
132    UnknownValue(serde_json::Value),
133}
134
135/// struct for typed errors of method [`list_group_billing_invoice_lines`]
136#[derive(Debug, Clone, Serialize, Deserialize)]
137#[serde(untagged)]
138pub enum ListGroupBillingInvoiceLinesError {
139    Status403(crate::models::Error),
140    Status404(crate::models::Error),
141    UnknownValue(serde_json::Value),
142}
143
144/// struct for typed errors of method [`list_group_billing_invoices`]
145#[derive(Debug, Clone, Serialize, Deserialize)]
146#[serde(untagged)]
147pub enum ListGroupBillingInvoicesError {
148    Status403(crate::models::Error),
149    Status404(crate::models::Error),
150    UnknownValue(serde_json::Value),
151}
152
153/// struct for typed errors of method [`list_group_upcoming_billing_invoice_lines`]
154#[derive(Debug, Clone, Serialize, Deserialize)]
155#[serde(untagged)]
156pub enum ListGroupUpcomingBillingInvoiceLinesError {
157    Status403(crate::models::Error),
158    Status404(crate::models::Error),
159    UnknownValue(serde_json::Value),
160}
161
162/// struct for typed errors of method [`list_group_users`]
163#[derive(Debug, Clone, Serialize, Deserialize)]
164#[serde(untagged)]
165pub enum ListGroupUsersError {
166    Status404(crate::models::Error),
167    Status422(crate::models::Error),
168    UnknownValue(serde_json::Value),
169}
170
171/// struct for typed errors of method [`list_user_billing_invoice_lines`]
172#[derive(Debug, Clone, Serialize, Deserialize)]
173#[serde(untagged)]
174pub enum ListUserBillingInvoiceLinesError {
175    Status403(crate::models::Error),
176    Status404(crate::models::Error),
177    UnknownValue(serde_json::Value),
178}
179
180/// struct for typed errors of method [`list_user_billing_invoices`]
181#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum ListUserBillingInvoicesError {
184    Status403(crate::models::Error),
185    Status404(crate::models::Error),
186    UnknownValue(serde_json::Value),
187}
188
189/// struct for typed errors of method [`list_user_groups`]
190#[derive(Debug, Clone, Serialize, Deserialize)]
191#[serde(untagged)]
192pub enum ListUserGroupsError {
193    Status422(crate::models::Error),
194    UnknownValue(serde_json::Value),
195}
196
197/// struct for typed errors of method [`list_user_upcoming_billing_invoice_lines`]
198#[derive(Debug, Clone, Serialize, Deserialize)]
199#[serde(untagged)]
200pub enum ListUserUpcomingBillingInvoiceLinesError {
201    Status403(crate::models::Error),
202    Status404(crate::models::Error),
203    UnknownValue(serde_json::Value),
204}
205
206/// struct for typed errors of method [`list_viewer_announcements`]
207#[derive(Debug, Clone, Serialize, Deserialize)]
208#[serde(untagged)]
209pub enum ListViewerAnnouncementsError {
210    Status401(crate::models::Error),
211    Status422(crate::models::Error),
212    UnknownValue(serde_json::Value),
213}
214
215/// struct for typed errors of method [`put_viewer_user_onboarding_completed`]
216#[derive(Debug, Clone, Serialize, Deserialize)]
217#[serde(untagged)]
218pub enum PutViewerUserOnboardingCompletedError {
219    Status401(crate::models::Error),
220    UnknownValue(serde_json::Value),
221}
222
223/// struct for typed errors of method [`remove_group_user`]
224#[derive(Debug, Clone, Serialize, Deserialize)]
225#[serde(untagged)]
226pub enum RemoveGroupUserError {
227    Status404(crate::models::Error),
228    Status422(crate::models::Error),
229    UnknownValue(serde_json::Value),
230}
231
232/// struct for typed errors of method [`update_viewer_user_profile`]
233#[derive(Debug, Clone, Serialize, Deserialize)]
234#[serde(untagged)]
235pub enum UpdateViewerUserProfileError {
236    Status401(crate::models::Error),
237    Status404(crate::models::Error),
238    Status422(crate::models::Error),
239    UnknownValue(serde_json::Value),
240}
241
242async fn activate_user_inner(
243    configuration: &configuration::Configuration,
244    backoff: &mut ExponentialBackoff,
245    activate_user_request: Option<crate::models::ActivateUserRequest>,
246) -> Result<crate::models::User, Error<ActivateUserError>> {
247    let local_var_configuration = configuration;
248
249    let local_var_client = &local_var_configuration.client;
250
251    let local_var_uri_str = format!(
252        "{}/v1/users:activate",
253        local_var_configuration.qcs_config.api_url()
254    );
255    let mut local_var_req_builder =
256        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
257
258    #[cfg(feature = "tracing")]
259    {
260        // Ignore parsing errors if the URL is invalid for some reason.
261        // If it is invalid, it will turn up as an error later when actually making the request.
262        let local_var_do_tracing =
263            local_var_uri_str
264                .parse::<::url::Url>()
265                .ok()
266                .map_or(true, |url| {
267                    configuration
268                        .qcs_config
269                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
270                });
271
272        if local_var_do_tracing {
273            ::tracing::debug!(
274                url=%local_var_uri_str,
275                method="POST",
276                "making activate_user request",
277            );
278        }
279    }
280
281    // Use the QCS Bearer token if a client OAuthSession is present,
282    // but do not require one when the security schema says it is optional.
283    {
284        use qcs_api_client_common::configuration::TokenError;
285
286        #[allow(
287            clippy::nonminimal_bool,
288            clippy::eq_op,
289            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
290        )]
291        let is_jwt_bearer_optional: bool = false;
292
293        let token = local_var_configuration
294            .qcs_config
295            .get_bearer_access_token()
296            .await;
297
298        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
299            // the client is configured without any OAuthSession, but this call does not require one.
300            #[cfg(feature = "tracing")]
301            tracing::debug!(
302                "No client credentials found, but this call does not require authentication."
303            );
304        } else {
305            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
306        }
307    }
308
309    local_var_req_builder = local_var_req_builder.json(&activate_user_request);
310
311    let local_var_req = local_var_req_builder.build()?;
312    let local_var_resp = local_var_client.execute(local_var_req).await?;
313
314    let local_var_status = local_var_resp.status();
315
316    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
317        let local_var_content = local_var_resp.text().await?;
318        serde_json::from_str(&local_var_content).map_err(Error::from)
319    } else {
320        let local_var_retry_delay =
321            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
322        let local_var_content = local_var_resp.text().await?;
323        let local_var_entity: Option<ActivateUserError> =
324            serde_json::from_str(&local_var_content).ok();
325        let local_var_error = ResponseContent {
326            status: local_var_status,
327            content: local_var_content,
328            entity: local_var_entity,
329            retry_delay: local_var_retry_delay,
330        };
331        Err(Error::ResponseError(local_var_error))
332    }
333}
334
335/// Activate a user, completing an invitation request.
336pub async fn activate_user(
337    configuration: &configuration::Configuration,
338    activate_user_request: Option<crate::models::ActivateUserRequest>,
339) -> Result<crate::models::User, Error<ActivateUserError>> {
340    let mut backoff = configuration.backoff.clone();
341    let mut refreshed_credentials = false;
342    let method = reqwest::Method::POST;
343    loop {
344        let result =
345            activate_user_inner(configuration, &mut backoff, activate_user_request.clone()).await;
346
347        match result {
348            Ok(result) => return Ok(result),
349            Err(Error::ResponseError(response)) => {
350                if !refreshed_credentials
351                    && matches!(
352                        response.status,
353                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
354                    )
355                {
356                    configuration.qcs_config.refresh().await?;
357                    refreshed_credentials = true;
358                    continue;
359                } else if let Some(duration) = response.retry_delay {
360                    tokio::time::sleep(duration).await;
361                    continue;
362                }
363
364                return Err(Error::ResponseError(response));
365            }
366            Err(Error::Reqwest(error)) => {
367                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
368                    tokio::time::sleep(duration).await;
369                    continue;
370                }
371
372                return Err(Error::Reqwest(error));
373            }
374            Err(Error::Io(error)) => {
375                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
376                    tokio::time::sleep(duration).await;
377                    continue;
378                }
379
380                return Err(Error::Io(error));
381            }
382            Err(error) => return Err(error),
383        }
384    }
385}
386async fn add_group_user_inner(
387    configuration: &configuration::Configuration,
388    backoff: &mut ExponentialBackoff,
389    add_group_user_request: crate::models::AddGroupUserRequest,
390) -> Result<(), Error<AddGroupUserError>> {
391    let local_var_configuration = configuration;
392
393    let local_var_client = &local_var_configuration.client;
394
395    let local_var_uri_str = format!(
396        "{}/v1/groups:addUser",
397        local_var_configuration.qcs_config.api_url()
398    );
399    let mut local_var_req_builder =
400        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
401
402    #[cfg(feature = "tracing")]
403    {
404        // Ignore parsing errors if the URL is invalid for some reason.
405        // If it is invalid, it will turn up as an error later when actually making the request.
406        let local_var_do_tracing =
407            local_var_uri_str
408                .parse::<::url::Url>()
409                .ok()
410                .map_or(true, |url| {
411                    configuration
412                        .qcs_config
413                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
414                });
415
416        if local_var_do_tracing {
417            ::tracing::debug!(
418                url=%local_var_uri_str,
419                method="POST",
420                "making add_group_user request",
421            );
422        }
423    }
424
425    // Use the QCS Bearer token if a client OAuthSession is present,
426    // but do not require one when the security schema says it is optional.
427    {
428        use qcs_api_client_common::configuration::TokenError;
429
430        #[allow(
431            clippy::nonminimal_bool,
432            clippy::eq_op,
433            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
434        )]
435        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
436
437        let token = local_var_configuration
438            .qcs_config
439            .get_bearer_access_token()
440            .await;
441
442        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
443            // the client is configured without any OAuthSession, but this call does not require one.
444            #[cfg(feature = "tracing")]
445            tracing::debug!(
446                "No client credentials found, but this call does not require authentication."
447            );
448        } else {
449            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
450        }
451    }
452
453    local_var_req_builder = local_var_req_builder.json(&add_group_user_request);
454
455    let local_var_req = local_var_req_builder.build()?;
456    let local_var_resp = local_var_client.execute(local_var_req).await?;
457
458    let local_var_status = local_var_resp.status();
459
460    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
461        Ok(())
462    } else {
463        let local_var_retry_delay =
464            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
465        let local_var_content = local_var_resp.text().await?;
466        let local_var_entity: Option<AddGroupUserError> =
467            serde_json::from_str(&local_var_content).ok();
468        let local_var_error = ResponseContent {
469            status: local_var_status,
470            content: local_var_content,
471            entity: local_var_entity,
472            retry_delay: local_var_retry_delay,
473        };
474        Err(Error::ResponseError(local_var_error))
475    }
476}
477
478/// Add a user to a group. Note, group membership may take several minutes to update within our identity provider. After adding a user to a group, please allow up to 60 minutes for changes to be reflected.
479pub async fn add_group_user(
480    configuration: &configuration::Configuration,
481    add_group_user_request: crate::models::AddGroupUserRequest,
482) -> Result<(), Error<AddGroupUserError>> {
483    let mut backoff = configuration.backoff.clone();
484    let mut refreshed_credentials = false;
485    let method = reqwest::Method::POST;
486    loop {
487        let result =
488            add_group_user_inner(configuration, &mut backoff, add_group_user_request.clone()).await;
489
490        match result {
491            Ok(result) => return Ok(result),
492            Err(Error::ResponseError(response)) => {
493                if !refreshed_credentials
494                    && matches!(
495                        response.status,
496                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
497                    )
498                {
499                    configuration.qcs_config.refresh().await?;
500                    refreshed_credentials = true;
501                    continue;
502                } else if let Some(duration) = response.retry_delay {
503                    tokio::time::sleep(duration).await;
504                    continue;
505                }
506
507                return Err(Error::ResponseError(response));
508            }
509            Err(Error::Reqwest(error)) => {
510                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
511                    tokio::time::sleep(duration).await;
512                    continue;
513                }
514
515                return Err(Error::Reqwest(error));
516            }
517            Err(Error::Io(error)) => {
518                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
519                    tokio::time::sleep(duration).await;
520                    continue;
521                }
522
523                return Err(Error::Io(error));
524            }
525            Err(error) => return Err(error),
526        }
527    }
528}
529async fn dismiss_viewer_announcement_inner(
530    configuration: &configuration::Configuration,
531    backoff: &mut ExponentialBackoff,
532    announcement_id: i64,
533) -> Result<(), Error<DismissViewerAnnouncementError>> {
534    let local_var_configuration = configuration;
535
536    let local_var_client = &local_var_configuration.client;
537
538    let local_var_uri_str = format!(
539        "{}/v1/viewer/announcements/{announcementId}",
540        local_var_configuration.qcs_config.api_url(),
541        announcementId = announcement_id
542    );
543    let mut local_var_req_builder =
544        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
545
546    #[cfg(feature = "tracing")]
547    {
548        // Ignore parsing errors if the URL is invalid for some reason.
549        // If it is invalid, it will turn up as an error later when actually making the request.
550        let local_var_do_tracing =
551            local_var_uri_str
552                .parse::<::url::Url>()
553                .ok()
554                .map_or(true, |url| {
555                    configuration
556                        .qcs_config
557                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
558                });
559
560        if local_var_do_tracing {
561            ::tracing::debug!(
562                url=%local_var_uri_str,
563                method="DELETE",
564                "making dismiss_viewer_announcement request",
565            );
566        }
567    }
568
569    // Use the QCS Bearer token if a client OAuthSession is present,
570    // but do not require one when the security schema says it is optional.
571    {
572        use qcs_api_client_common::configuration::TokenError;
573
574        #[allow(
575            clippy::nonminimal_bool,
576            clippy::eq_op,
577            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
578        )]
579        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
580
581        let token = local_var_configuration
582            .qcs_config
583            .get_bearer_access_token()
584            .await;
585
586        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
587            // the client is configured without any OAuthSession, but this call does not require one.
588            #[cfg(feature = "tracing")]
589            tracing::debug!(
590                "No client credentials found, but this call does not require authentication."
591            );
592        } else {
593            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
594        }
595    }
596
597    let local_var_req = local_var_req_builder.build()?;
598    let local_var_resp = local_var_client.execute(local_var_req).await?;
599
600    let local_var_status = local_var_resp.status();
601
602    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
603        Ok(())
604    } else {
605        let local_var_retry_delay =
606            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
607        let local_var_content = local_var_resp.text().await?;
608        let local_var_entity: Option<DismissViewerAnnouncementError> =
609            serde_json::from_str(&local_var_content).ok();
610        let local_var_error = ResponseContent {
611            status: local_var_status,
612            content: local_var_content,
613            entity: local_var_entity,
614            retry_delay: local_var_retry_delay,
615        };
616        Err(Error::ResponseError(local_var_error))
617    }
618}
619
620/// Dismiss an announcement for an authenticating user, indicating that they do not want to see it again.
621pub async fn dismiss_viewer_announcement(
622    configuration: &configuration::Configuration,
623    announcement_id: i64,
624) -> Result<(), Error<DismissViewerAnnouncementError>> {
625    let mut backoff = configuration.backoff.clone();
626    let mut refreshed_credentials = false;
627    let method = reqwest::Method::DELETE;
628    loop {
629        let result =
630            dismiss_viewer_announcement_inner(configuration, &mut backoff, announcement_id.clone())
631                .await;
632
633        match result {
634            Ok(result) => return Ok(result),
635            Err(Error::ResponseError(response)) => {
636                if !refreshed_credentials
637                    && matches!(
638                        response.status,
639                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
640                    )
641                {
642                    configuration.qcs_config.refresh().await?;
643                    refreshed_credentials = true;
644                    continue;
645                } else if let Some(duration) = response.retry_delay {
646                    tokio::time::sleep(duration).await;
647                    continue;
648                }
649
650                return Err(Error::ResponseError(response));
651            }
652            Err(Error::Reqwest(error)) => {
653                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
654                    tokio::time::sleep(duration).await;
655                    continue;
656                }
657
658                return Err(Error::Reqwest(error));
659            }
660            Err(Error::Io(error)) => {
661                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
662                    tokio::time::sleep(duration).await;
663                    continue;
664                }
665
666                return Err(Error::Io(error));
667            }
668            Err(error) => return Err(error),
669        }
670    }
671}
672async fn get_group_balance_inner(
673    configuration: &configuration::Configuration,
674    backoff: &mut ExponentialBackoff,
675    group_name: &str,
676) -> Result<crate::models::AccountBalance, Error<GetGroupBalanceError>> {
677    let local_var_configuration = configuration;
678
679    let local_var_client = &local_var_configuration.client;
680
681    let local_var_uri_str = format!(
682        "{}/v1/groups/{groupName}/balance",
683        local_var_configuration.qcs_config.api_url(),
684        groupName = crate::apis::urlencode(group_name)
685    );
686    let mut local_var_req_builder =
687        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
688
689    #[cfg(feature = "tracing")]
690    {
691        // Ignore parsing errors if the URL is invalid for some reason.
692        // If it is invalid, it will turn up as an error later when actually making the request.
693        let local_var_do_tracing =
694            local_var_uri_str
695                .parse::<::url::Url>()
696                .ok()
697                .map_or(true, |url| {
698                    configuration
699                        .qcs_config
700                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
701                });
702
703        if local_var_do_tracing {
704            ::tracing::debug!(
705                url=%local_var_uri_str,
706                method="GET",
707                "making get_group_balance request",
708            );
709        }
710    }
711
712    // Use the QCS Bearer token if a client OAuthSession is present,
713    // but do not require one when the security schema says it is optional.
714    {
715        use qcs_api_client_common::configuration::TokenError;
716
717        #[allow(
718            clippy::nonminimal_bool,
719            clippy::eq_op,
720            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
721        )]
722        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
723
724        let token = local_var_configuration
725            .qcs_config
726            .get_bearer_access_token()
727            .await;
728
729        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
730            // the client is configured without any OAuthSession, but this call does not require one.
731            #[cfg(feature = "tracing")]
732            tracing::debug!(
733                "No client credentials found, but this call does not require authentication."
734            );
735        } else {
736            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
737        }
738    }
739
740    let local_var_req = local_var_req_builder.build()?;
741    let local_var_resp = local_var_client.execute(local_var_req).await?;
742
743    let local_var_status = local_var_resp.status();
744
745    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
746        let local_var_content = local_var_resp.text().await?;
747        serde_json::from_str(&local_var_content).map_err(Error::from)
748    } else {
749        let local_var_retry_delay =
750            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
751        let local_var_content = local_var_resp.text().await?;
752        let local_var_entity: Option<GetGroupBalanceError> =
753            serde_json::from_str(&local_var_content).ok();
754        let local_var_error = ResponseContent {
755            status: local_var_status,
756            content: local_var_content,
757            entity: local_var_entity,
758            retry_delay: local_var_retry_delay,
759        };
760        Err(Error::ResponseError(local_var_error))
761    }
762}
763
764/// Retrieve the balance of the requested QCS group account.
765pub async fn get_group_balance(
766    configuration: &configuration::Configuration,
767    group_name: &str,
768) -> Result<crate::models::AccountBalance, Error<GetGroupBalanceError>> {
769    let mut backoff = configuration.backoff.clone();
770    let mut refreshed_credentials = false;
771    let method = reqwest::Method::GET;
772    loop {
773        let result = get_group_balance_inner(configuration, &mut backoff, group_name.clone()).await;
774
775        match result {
776            Ok(result) => return Ok(result),
777            Err(Error::ResponseError(response)) => {
778                if !refreshed_credentials
779                    && matches!(
780                        response.status,
781                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
782                    )
783                {
784                    configuration.qcs_config.refresh().await?;
785                    refreshed_credentials = true;
786                    continue;
787                } else if let Some(duration) = response.retry_delay {
788                    tokio::time::sleep(duration).await;
789                    continue;
790                }
791
792                return Err(Error::ResponseError(response));
793            }
794            Err(Error::Reqwest(error)) => {
795                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
796                    tokio::time::sleep(duration).await;
797                    continue;
798                }
799
800                return Err(Error::Reqwest(error));
801            }
802            Err(Error::Io(error)) => {
803                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
804                    tokio::time::sleep(duration).await;
805                    continue;
806                }
807
808                return Err(Error::Io(error));
809            }
810            Err(error) => return Err(error),
811        }
812    }
813}
814async fn get_group_billing_customer_inner(
815    configuration: &configuration::Configuration,
816    backoff: &mut ExponentialBackoff,
817    group_name: &str,
818) -> Result<crate::models::BillingCustomer, Error<GetGroupBillingCustomerError>> {
819    let local_var_configuration = configuration;
820
821    let local_var_client = &local_var_configuration.client;
822
823    let local_var_uri_str = format!(
824        "{}/v1/groups/{groupName}/billingCustomer",
825        local_var_configuration.qcs_config.api_url(),
826        groupName = crate::apis::urlencode(group_name)
827    );
828    let mut local_var_req_builder =
829        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
830
831    #[cfg(feature = "tracing")]
832    {
833        // Ignore parsing errors if the URL is invalid for some reason.
834        // If it is invalid, it will turn up as an error later when actually making the request.
835        let local_var_do_tracing =
836            local_var_uri_str
837                .parse::<::url::Url>()
838                .ok()
839                .map_or(true, |url| {
840                    configuration
841                        .qcs_config
842                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
843                });
844
845        if local_var_do_tracing {
846            ::tracing::debug!(
847                url=%local_var_uri_str,
848                method="GET",
849                "making get_group_billing_customer request",
850            );
851        }
852    }
853
854    // Use the QCS Bearer token if a client OAuthSession is present,
855    // but do not require one when the security schema says it is optional.
856    {
857        use qcs_api_client_common::configuration::TokenError;
858
859        #[allow(
860            clippy::nonminimal_bool,
861            clippy::eq_op,
862            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
863        )]
864        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
865
866        let token = local_var_configuration
867            .qcs_config
868            .get_bearer_access_token()
869            .await;
870
871        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
872            // the client is configured without any OAuthSession, but this call does not require one.
873            #[cfg(feature = "tracing")]
874            tracing::debug!(
875                "No client credentials found, but this call does not require authentication."
876            );
877        } else {
878            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
879        }
880    }
881
882    let local_var_req = local_var_req_builder.build()?;
883    let local_var_resp = local_var_client.execute(local_var_req).await?;
884
885    let local_var_status = local_var_resp.status();
886
887    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
888        let local_var_content = local_var_resp.text().await?;
889        serde_json::from_str(&local_var_content).map_err(Error::from)
890    } else {
891        let local_var_retry_delay =
892            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
893        let local_var_content = local_var_resp.text().await?;
894        let local_var_entity: Option<GetGroupBillingCustomerError> =
895            serde_json::from_str(&local_var_content).ok();
896        let local_var_error = ResponseContent {
897            status: local_var_status,
898            content: local_var_content,
899            entity: local_var_entity,
900            retry_delay: local_var_retry_delay,
901        };
902        Err(Error::ResponseError(local_var_error))
903    }
904}
905
906/// Retrieve billing customer for a QCS group account.
907pub async fn get_group_billing_customer(
908    configuration: &configuration::Configuration,
909    group_name: &str,
910) -> Result<crate::models::BillingCustomer, Error<GetGroupBillingCustomerError>> {
911    let mut backoff = configuration.backoff.clone();
912    let mut refreshed_credentials = false;
913    let method = reqwest::Method::GET;
914    loop {
915        let result =
916            get_group_billing_customer_inner(configuration, &mut backoff, group_name.clone()).await;
917
918        match result {
919            Ok(result) => return Ok(result),
920            Err(Error::ResponseError(response)) => {
921                if !refreshed_credentials
922                    && matches!(
923                        response.status,
924                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
925                    )
926                {
927                    configuration.qcs_config.refresh().await?;
928                    refreshed_credentials = true;
929                    continue;
930                } else if let Some(duration) = response.retry_delay {
931                    tokio::time::sleep(duration).await;
932                    continue;
933                }
934
935                return Err(Error::ResponseError(response));
936            }
937            Err(Error::Reqwest(error)) => {
938                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
939                    tokio::time::sleep(duration).await;
940                    continue;
941                }
942
943                return Err(Error::Reqwest(error));
944            }
945            Err(Error::Io(error)) => {
946                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
947                    tokio::time::sleep(duration).await;
948                    continue;
949                }
950
951                return Err(Error::Io(error));
952            }
953            Err(error) => return Err(error),
954        }
955    }
956}
957async fn get_group_upcoming_billing_invoice_inner(
958    configuration: &configuration::Configuration,
959    backoff: &mut ExponentialBackoff,
960    group_name: &str,
961) -> Result<crate::models::BillingUpcomingInvoice, Error<GetGroupUpcomingBillingInvoiceError>> {
962    let local_var_configuration = configuration;
963
964    let local_var_client = &local_var_configuration.client;
965
966    let local_var_uri_str = format!(
967        "{}/v1/groups/{groupName}/billingInvoices:getUpcoming",
968        local_var_configuration.qcs_config.api_url(),
969        groupName = crate::apis::urlencode(group_name)
970    );
971    let mut local_var_req_builder =
972        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
973
974    #[cfg(feature = "tracing")]
975    {
976        // Ignore parsing errors if the URL is invalid for some reason.
977        // If it is invalid, it will turn up as an error later when actually making the request.
978        let local_var_do_tracing =
979            local_var_uri_str
980                .parse::<::url::Url>()
981                .ok()
982                .map_or(true, |url| {
983                    configuration
984                        .qcs_config
985                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
986                });
987
988        if local_var_do_tracing {
989            ::tracing::debug!(
990                url=%local_var_uri_str,
991                method="GET",
992                "making get_group_upcoming_billing_invoice request",
993            );
994        }
995    }
996
997    // Use the QCS Bearer token if a client OAuthSession is present,
998    // but do not require one when the security schema says it is optional.
999    {
1000        use qcs_api_client_common::configuration::TokenError;
1001
1002        #[allow(
1003            clippy::nonminimal_bool,
1004            clippy::eq_op,
1005            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1006        )]
1007        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1008
1009        let token = local_var_configuration
1010            .qcs_config
1011            .get_bearer_access_token()
1012            .await;
1013
1014        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1015            // the client is configured without any OAuthSession, but this call does not require one.
1016            #[cfg(feature = "tracing")]
1017            tracing::debug!(
1018                "No client credentials found, but this call does not require authentication."
1019            );
1020        } else {
1021            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
1022        }
1023    }
1024
1025    let local_var_req = local_var_req_builder.build()?;
1026    let local_var_resp = local_var_client.execute(local_var_req).await?;
1027
1028    let local_var_status = local_var_resp.status();
1029
1030    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1031        let local_var_content = local_var_resp.text().await?;
1032        serde_json::from_str(&local_var_content).map_err(Error::from)
1033    } else {
1034        let local_var_retry_delay =
1035            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1036        let local_var_content = local_var_resp.text().await?;
1037        let local_var_entity: Option<GetGroupUpcomingBillingInvoiceError> =
1038            serde_json::from_str(&local_var_content).ok();
1039        let local_var_error = ResponseContent {
1040            status: local_var_status,
1041            content: local_var_content,
1042            entity: local_var_entity,
1043            retry_delay: local_var_retry_delay,
1044        };
1045        Err(Error::ResponseError(local_var_error))
1046    }
1047}
1048
1049/// Retrieve upcoming invoice for QCS group billing customer.
1050pub async fn get_group_upcoming_billing_invoice(
1051    configuration: &configuration::Configuration,
1052    group_name: &str,
1053) -> Result<crate::models::BillingUpcomingInvoice, Error<GetGroupUpcomingBillingInvoiceError>> {
1054    let mut backoff = configuration.backoff.clone();
1055    let mut refreshed_credentials = false;
1056    let method = reqwest::Method::GET;
1057    loop {
1058        let result = get_group_upcoming_billing_invoice_inner(
1059            configuration,
1060            &mut backoff,
1061            group_name.clone(),
1062        )
1063        .await;
1064
1065        match result {
1066            Ok(result) => return Ok(result),
1067            Err(Error::ResponseError(response)) => {
1068                if !refreshed_credentials
1069                    && matches!(
1070                        response.status,
1071                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1072                    )
1073                {
1074                    configuration.qcs_config.refresh().await?;
1075                    refreshed_credentials = true;
1076                    continue;
1077                } else if let Some(duration) = response.retry_delay {
1078                    tokio::time::sleep(duration).await;
1079                    continue;
1080                }
1081
1082                return Err(Error::ResponseError(response));
1083            }
1084            Err(Error::Reqwest(error)) => {
1085                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1086                    tokio::time::sleep(duration).await;
1087                    continue;
1088                }
1089
1090                return Err(Error::Reqwest(error));
1091            }
1092            Err(Error::Io(error)) => {
1093                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1094                    tokio::time::sleep(duration).await;
1095                    continue;
1096                }
1097
1098                return Err(Error::Io(error));
1099            }
1100            Err(error) => return Err(error),
1101        }
1102    }
1103}
1104async fn get_user_balance_inner(
1105    configuration: &configuration::Configuration,
1106    backoff: &mut ExponentialBackoff,
1107    user_id: &str,
1108) -> Result<crate::models::AccountBalance, Error<GetUserBalanceError>> {
1109    let local_var_configuration = configuration;
1110
1111    let local_var_client = &local_var_configuration.client;
1112
1113    let local_var_uri_str = format!(
1114        "{}/v1/users/{userId}/balance",
1115        local_var_configuration.qcs_config.api_url(),
1116        userId = crate::apis::urlencode(user_id)
1117    );
1118    let mut local_var_req_builder =
1119        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1120
1121    #[cfg(feature = "tracing")]
1122    {
1123        // Ignore parsing errors if the URL is invalid for some reason.
1124        // If it is invalid, it will turn up as an error later when actually making the request.
1125        let local_var_do_tracing =
1126            local_var_uri_str
1127                .parse::<::url::Url>()
1128                .ok()
1129                .map_or(true, |url| {
1130                    configuration
1131                        .qcs_config
1132                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1133                });
1134
1135        if local_var_do_tracing {
1136            ::tracing::debug!(
1137                url=%local_var_uri_str,
1138                method="GET",
1139                "making get_user_balance request",
1140            );
1141        }
1142    }
1143
1144    // Use the QCS Bearer token if a client OAuthSession is present,
1145    // but do not require one when the security schema says it is optional.
1146    {
1147        use qcs_api_client_common::configuration::TokenError;
1148
1149        #[allow(
1150            clippy::nonminimal_bool,
1151            clippy::eq_op,
1152            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1153        )]
1154        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1155
1156        let token = local_var_configuration
1157            .qcs_config
1158            .get_bearer_access_token()
1159            .await;
1160
1161        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1162            // the client is configured without any OAuthSession, but this call does not require one.
1163            #[cfg(feature = "tracing")]
1164            tracing::debug!(
1165                "No client credentials found, but this call does not require authentication."
1166            );
1167        } else {
1168            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
1169        }
1170    }
1171
1172    let local_var_req = local_var_req_builder.build()?;
1173    let local_var_resp = local_var_client.execute(local_var_req).await?;
1174
1175    let local_var_status = local_var_resp.status();
1176
1177    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1178        let local_var_content = local_var_resp.text().await?;
1179        serde_json::from_str(&local_var_content).map_err(Error::from)
1180    } else {
1181        let local_var_retry_delay =
1182            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1183        let local_var_content = local_var_resp.text().await?;
1184        let local_var_entity: Option<GetUserBalanceError> =
1185            serde_json::from_str(&local_var_content).ok();
1186        let local_var_error = ResponseContent {
1187            status: local_var_status,
1188            content: local_var_content,
1189            entity: local_var_entity,
1190            retry_delay: local_var_retry_delay,
1191        };
1192        Err(Error::ResponseError(local_var_error))
1193    }
1194}
1195
1196/// Retrieve the balance of the requested QCS user account.
1197pub async fn get_user_balance(
1198    configuration: &configuration::Configuration,
1199    user_id: &str,
1200) -> Result<crate::models::AccountBalance, Error<GetUserBalanceError>> {
1201    let mut backoff = configuration.backoff.clone();
1202    let mut refreshed_credentials = false;
1203    let method = reqwest::Method::GET;
1204    loop {
1205        let result = get_user_balance_inner(configuration, &mut backoff, user_id.clone()).await;
1206
1207        match result {
1208            Ok(result) => return Ok(result),
1209            Err(Error::ResponseError(response)) => {
1210                if !refreshed_credentials
1211                    && matches!(
1212                        response.status,
1213                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1214                    )
1215                {
1216                    configuration.qcs_config.refresh().await?;
1217                    refreshed_credentials = true;
1218                    continue;
1219                } else if let Some(duration) = response.retry_delay {
1220                    tokio::time::sleep(duration).await;
1221                    continue;
1222                }
1223
1224                return Err(Error::ResponseError(response));
1225            }
1226            Err(Error::Reqwest(error)) => {
1227                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1228                    tokio::time::sleep(duration).await;
1229                    continue;
1230                }
1231
1232                return Err(Error::Reqwest(error));
1233            }
1234            Err(Error::Io(error)) => {
1235                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1236                    tokio::time::sleep(duration).await;
1237                    continue;
1238                }
1239
1240                return Err(Error::Io(error));
1241            }
1242            Err(error) => return Err(error),
1243        }
1244    }
1245}
1246async fn get_user_billing_customer_inner(
1247    configuration: &configuration::Configuration,
1248    backoff: &mut ExponentialBackoff,
1249    user_id: &str,
1250) -> Result<crate::models::BillingCustomer, Error<GetUserBillingCustomerError>> {
1251    let local_var_configuration = configuration;
1252
1253    let local_var_client = &local_var_configuration.client;
1254
1255    let local_var_uri_str = format!(
1256        "{}/v1/users/{userId}/billingCustomer",
1257        local_var_configuration.qcs_config.api_url(),
1258        userId = crate::apis::urlencode(user_id)
1259    );
1260    let mut local_var_req_builder =
1261        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1262
1263    #[cfg(feature = "tracing")]
1264    {
1265        // Ignore parsing errors if the URL is invalid for some reason.
1266        // If it is invalid, it will turn up as an error later when actually making the request.
1267        let local_var_do_tracing =
1268            local_var_uri_str
1269                .parse::<::url::Url>()
1270                .ok()
1271                .map_or(true, |url| {
1272                    configuration
1273                        .qcs_config
1274                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1275                });
1276
1277        if local_var_do_tracing {
1278            ::tracing::debug!(
1279                url=%local_var_uri_str,
1280                method="GET",
1281                "making get_user_billing_customer request",
1282            );
1283        }
1284    }
1285
1286    // Use the QCS Bearer token if a client OAuthSession is present,
1287    // but do not require one when the security schema says it is optional.
1288    {
1289        use qcs_api_client_common::configuration::TokenError;
1290
1291        #[allow(
1292            clippy::nonminimal_bool,
1293            clippy::eq_op,
1294            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1295        )]
1296        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1297
1298        let token = local_var_configuration
1299            .qcs_config
1300            .get_bearer_access_token()
1301            .await;
1302
1303        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1304            // the client is configured without any OAuthSession, but this call does not require one.
1305            #[cfg(feature = "tracing")]
1306            tracing::debug!(
1307                "No client credentials found, but this call does not require authentication."
1308            );
1309        } else {
1310            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
1311        }
1312    }
1313
1314    let local_var_req = local_var_req_builder.build()?;
1315    let local_var_resp = local_var_client.execute(local_var_req).await?;
1316
1317    let local_var_status = local_var_resp.status();
1318
1319    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1320        let local_var_content = local_var_resp.text().await?;
1321        serde_json::from_str(&local_var_content).map_err(Error::from)
1322    } else {
1323        let local_var_retry_delay =
1324            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1325        let local_var_content = local_var_resp.text().await?;
1326        let local_var_entity: Option<GetUserBillingCustomerError> =
1327            serde_json::from_str(&local_var_content).ok();
1328        let local_var_error = ResponseContent {
1329            status: local_var_status,
1330            content: local_var_content,
1331            entity: local_var_entity,
1332            retry_delay: local_var_retry_delay,
1333        };
1334        Err(Error::ResponseError(local_var_error))
1335    }
1336}
1337
1338/// Retrieve billing customer for a QCS user account.
1339pub async fn get_user_billing_customer(
1340    configuration: &configuration::Configuration,
1341    user_id: &str,
1342) -> Result<crate::models::BillingCustomer, Error<GetUserBillingCustomerError>> {
1343    let mut backoff = configuration.backoff.clone();
1344    let mut refreshed_credentials = false;
1345    let method = reqwest::Method::GET;
1346    loop {
1347        let result =
1348            get_user_billing_customer_inner(configuration, &mut backoff, user_id.clone()).await;
1349
1350        match result {
1351            Ok(result) => return Ok(result),
1352            Err(Error::ResponseError(response)) => {
1353                if !refreshed_credentials
1354                    && matches!(
1355                        response.status,
1356                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1357                    )
1358                {
1359                    configuration.qcs_config.refresh().await?;
1360                    refreshed_credentials = true;
1361                    continue;
1362                } else if let Some(duration) = response.retry_delay {
1363                    tokio::time::sleep(duration).await;
1364                    continue;
1365                }
1366
1367                return Err(Error::ResponseError(response));
1368            }
1369            Err(Error::Reqwest(error)) => {
1370                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1371                    tokio::time::sleep(duration).await;
1372                    continue;
1373                }
1374
1375                return Err(Error::Reqwest(error));
1376            }
1377            Err(Error::Io(error)) => {
1378                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1379                    tokio::time::sleep(duration).await;
1380                    continue;
1381                }
1382
1383                return Err(Error::Io(error));
1384            }
1385            Err(error) => return Err(error),
1386        }
1387    }
1388}
1389async fn get_user_event_billing_price_inner(
1390    configuration: &configuration::Configuration,
1391    backoff: &mut ExponentialBackoff,
1392    user_id: &str,
1393    get_account_event_billing_price_request: crate::models::GetAccountEventBillingPriceRequest,
1394) -> Result<crate::models::EventBillingPriceRate, Error<GetUserEventBillingPriceError>> {
1395    let local_var_configuration = configuration;
1396
1397    let local_var_client = &local_var_configuration.client;
1398
1399    let local_var_uri_str = format!(
1400        "{}/v1/users/{userId}/eventBillingPrices:get",
1401        local_var_configuration.qcs_config.api_url(),
1402        userId = crate::apis::urlencode(user_id)
1403    );
1404    let mut local_var_req_builder =
1405        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
1406
1407    #[cfg(feature = "tracing")]
1408    {
1409        // Ignore parsing errors if the URL is invalid for some reason.
1410        // If it is invalid, it will turn up as an error later when actually making the request.
1411        let local_var_do_tracing =
1412            local_var_uri_str
1413                .parse::<::url::Url>()
1414                .ok()
1415                .map_or(true, |url| {
1416                    configuration
1417                        .qcs_config
1418                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1419                });
1420
1421        if local_var_do_tracing {
1422            ::tracing::debug!(
1423                url=%local_var_uri_str,
1424                method="POST",
1425                "making get_user_event_billing_price request",
1426            );
1427        }
1428    }
1429
1430    // Use the QCS Bearer token if a client OAuthSession is present,
1431    // but do not require one when the security schema says it is optional.
1432    {
1433        use qcs_api_client_common::configuration::TokenError;
1434
1435        #[allow(
1436            clippy::nonminimal_bool,
1437            clippy::eq_op,
1438            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1439        )]
1440        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1441
1442        let token = local_var_configuration
1443            .qcs_config
1444            .get_bearer_access_token()
1445            .await;
1446
1447        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1448            // the client is configured without any OAuthSession, but this call does not require one.
1449            #[cfg(feature = "tracing")]
1450            tracing::debug!(
1451                "No client credentials found, but this call does not require authentication."
1452            );
1453        } else {
1454            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
1455        }
1456    }
1457
1458    local_var_req_builder = local_var_req_builder.json(&get_account_event_billing_price_request);
1459
1460    let local_var_req = local_var_req_builder.build()?;
1461    let local_var_resp = local_var_client.execute(local_var_req).await?;
1462
1463    let local_var_status = local_var_resp.status();
1464
1465    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1466        let local_var_content = local_var_resp.text().await?;
1467        serde_json::from_str(&local_var_content).map_err(Error::from)
1468    } else {
1469        let local_var_retry_delay =
1470            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1471        let local_var_content = local_var_resp.text().await?;
1472        let local_var_entity: Option<GetUserEventBillingPriceError> =
1473            serde_json::from_str(&local_var_content).ok();
1474        let local_var_error = ResponseContent {
1475            status: local_var_status,
1476            content: local_var_content,
1477            entity: local_var_entity,
1478            retry_delay: local_var_retry_delay,
1479        };
1480        Err(Error::ResponseError(local_var_error))
1481    }
1482}
1483
1484/// Retrieve `EventBillingPrice` for a user for a specific event. If no price is configured this operation will return a default `EventBillingPrice` for the specified `product`.
1485pub async fn get_user_event_billing_price(
1486    configuration: &configuration::Configuration,
1487    user_id: &str,
1488    get_account_event_billing_price_request: crate::models::GetAccountEventBillingPriceRequest,
1489) -> Result<crate::models::EventBillingPriceRate, Error<GetUserEventBillingPriceError>> {
1490    let mut backoff = configuration.backoff.clone();
1491    let mut refreshed_credentials = false;
1492    let method = reqwest::Method::POST;
1493    loop {
1494        let result = get_user_event_billing_price_inner(
1495            configuration,
1496            &mut backoff,
1497            user_id.clone(),
1498            get_account_event_billing_price_request.clone(),
1499        )
1500        .await;
1501
1502        match result {
1503            Ok(result) => return Ok(result),
1504            Err(Error::ResponseError(response)) => {
1505                if !refreshed_credentials
1506                    && matches!(
1507                        response.status,
1508                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1509                    )
1510                {
1511                    configuration.qcs_config.refresh().await?;
1512                    refreshed_credentials = true;
1513                    continue;
1514                } else if let Some(duration) = response.retry_delay {
1515                    tokio::time::sleep(duration).await;
1516                    continue;
1517                }
1518
1519                return Err(Error::ResponseError(response));
1520            }
1521            Err(Error::Reqwest(error)) => {
1522                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1523                    tokio::time::sleep(duration).await;
1524                    continue;
1525                }
1526
1527                return Err(Error::Reqwest(error));
1528            }
1529            Err(Error::Io(error)) => {
1530                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1531                    tokio::time::sleep(duration).await;
1532                    continue;
1533                }
1534
1535                return Err(Error::Io(error));
1536            }
1537            Err(error) => return Err(error),
1538        }
1539    }
1540}
1541async fn get_user_upcoming_billing_invoice_inner(
1542    configuration: &configuration::Configuration,
1543    backoff: &mut ExponentialBackoff,
1544    user_id: &str,
1545) -> Result<crate::models::BillingUpcomingInvoice, Error<GetUserUpcomingBillingInvoiceError>> {
1546    let local_var_configuration = configuration;
1547
1548    let local_var_client = &local_var_configuration.client;
1549
1550    let local_var_uri_str = format!(
1551        "{}/v1/users/{userId}/billingInvoices:getUpcoming",
1552        local_var_configuration.qcs_config.api_url(),
1553        userId = crate::apis::urlencode(user_id)
1554    );
1555    let mut local_var_req_builder =
1556        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1557
1558    #[cfg(feature = "tracing")]
1559    {
1560        // Ignore parsing errors if the URL is invalid for some reason.
1561        // If it is invalid, it will turn up as an error later when actually making the request.
1562        let local_var_do_tracing =
1563            local_var_uri_str
1564                .parse::<::url::Url>()
1565                .ok()
1566                .map_or(true, |url| {
1567                    configuration
1568                        .qcs_config
1569                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1570                });
1571
1572        if local_var_do_tracing {
1573            ::tracing::debug!(
1574                url=%local_var_uri_str,
1575                method="GET",
1576                "making get_user_upcoming_billing_invoice request",
1577            );
1578        }
1579    }
1580
1581    // Use the QCS Bearer token if a client OAuthSession is present,
1582    // but do not require one when the security schema says it is optional.
1583    {
1584        use qcs_api_client_common::configuration::TokenError;
1585
1586        #[allow(
1587            clippy::nonminimal_bool,
1588            clippy::eq_op,
1589            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1590        )]
1591        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1592
1593        let token = local_var_configuration
1594            .qcs_config
1595            .get_bearer_access_token()
1596            .await;
1597
1598        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1599            // the client is configured without any OAuthSession, but this call does not require one.
1600            #[cfg(feature = "tracing")]
1601            tracing::debug!(
1602                "No client credentials found, but this call does not require authentication."
1603            );
1604        } else {
1605            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
1606        }
1607    }
1608
1609    let local_var_req = local_var_req_builder.build()?;
1610    let local_var_resp = local_var_client.execute(local_var_req).await?;
1611
1612    let local_var_status = local_var_resp.status();
1613
1614    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1615        let local_var_content = local_var_resp.text().await?;
1616        serde_json::from_str(&local_var_content).map_err(Error::from)
1617    } else {
1618        let local_var_retry_delay =
1619            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1620        let local_var_content = local_var_resp.text().await?;
1621        let local_var_entity: Option<GetUserUpcomingBillingInvoiceError> =
1622            serde_json::from_str(&local_var_content).ok();
1623        let local_var_error = ResponseContent {
1624            status: local_var_status,
1625            content: local_var_content,
1626            entity: local_var_entity,
1627            retry_delay: local_var_retry_delay,
1628        };
1629        Err(Error::ResponseError(local_var_error))
1630    }
1631}
1632
1633/// Retrieve upcoming invoice for QCS user billing customer.
1634pub async fn get_user_upcoming_billing_invoice(
1635    configuration: &configuration::Configuration,
1636    user_id: &str,
1637) -> Result<crate::models::BillingUpcomingInvoice, Error<GetUserUpcomingBillingInvoiceError>> {
1638    let mut backoff = configuration.backoff.clone();
1639    let mut refreshed_credentials = false;
1640    let method = reqwest::Method::GET;
1641    loop {
1642        let result =
1643            get_user_upcoming_billing_invoice_inner(configuration, &mut backoff, user_id.clone())
1644                .await;
1645
1646        match result {
1647            Ok(result) => return Ok(result),
1648            Err(Error::ResponseError(response)) => {
1649                if !refreshed_credentials
1650                    && matches!(
1651                        response.status,
1652                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1653                    )
1654                {
1655                    configuration.qcs_config.refresh().await?;
1656                    refreshed_credentials = true;
1657                    continue;
1658                } else if let Some(duration) = response.retry_delay {
1659                    tokio::time::sleep(duration).await;
1660                    continue;
1661                }
1662
1663                return Err(Error::ResponseError(response));
1664            }
1665            Err(Error::Reqwest(error)) => {
1666                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1667                    tokio::time::sleep(duration).await;
1668                    continue;
1669                }
1670
1671                return Err(Error::Reqwest(error));
1672            }
1673            Err(Error::Io(error)) => {
1674                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1675                    tokio::time::sleep(duration).await;
1676                    continue;
1677                }
1678
1679                return Err(Error::Io(error));
1680            }
1681            Err(error) => return Err(error),
1682        }
1683    }
1684}
1685async fn get_viewer_user_onboarding_completed_inner(
1686    configuration: &configuration::Configuration,
1687    backoff: &mut ExponentialBackoff,
1688) -> Result<
1689    crate::models::ViewerUserOnboardingCompleted,
1690    Error<GetViewerUserOnboardingCompletedError>,
1691> {
1692    let local_var_configuration = configuration;
1693
1694    let local_var_client = &local_var_configuration.client;
1695
1696    let local_var_uri_str = format!(
1697        "{}/v1/viewer/onboardingCompleted",
1698        local_var_configuration.qcs_config.api_url()
1699    );
1700    let mut local_var_req_builder =
1701        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1702
1703    #[cfg(feature = "tracing")]
1704    {
1705        // Ignore parsing errors if the URL is invalid for some reason.
1706        // If it is invalid, it will turn up as an error later when actually making the request.
1707        let local_var_do_tracing =
1708            local_var_uri_str
1709                .parse::<::url::Url>()
1710                .ok()
1711                .map_or(true, |url| {
1712                    configuration
1713                        .qcs_config
1714                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1715                });
1716
1717        if local_var_do_tracing {
1718            ::tracing::debug!(
1719                url=%local_var_uri_str,
1720                method="GET",
1721                "making get_viewer_user_onboarding_completed request",
1722            );
1723        }
1724    }
1725
1726    // Use the QCS Bearer token if a client OAuthSession is present,
1727    // but do not require one when the security schema says it is optional.
1728    {
1729        use qcs_api_client_common::configuration::TokenError;
1730
1731        #[allow(
1732            clippy::nonminimal_bool,
1733            clippy::eq_op,
1734            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1735        )]
1736        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1737
1738        let token = local_var_configuration
1739            .qcs_config
1740            .get_bearer_access_token()
1741            .await;
1742
1743        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1744            // the client is configured without any OAuthSession, but this call does not require one.
1745            #[cfg(feature = "tracing")]
1746            tracing::debug!(
1747                "No client credentials found, but this call does not require authentication."
1748            );
1749        } else {
1750            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
1751        }
1752    }
1753
1754    let local_var_req = local_var_req_builder.build()?;
1755    let local_var_resp = local_var_client.execute(local_var_req).await?;
1756
1757    let local_var_status = local_var_resp.status();
1758
1759    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1760        let local_var_content = local_var_resp.text().await?;
1761        serde_json::from_str(&local_var_content).map_err(Error::from)
1762    } else {
1763        let local_var_retry_delay =
1764            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1765        let local_var_content = local_var_resp.text().await?;
1766        let local_var_entity: Option<GetViewerUserOnboardingCompletedError> =
1767            serde_json::from_str(&local_var_content).ok();
1768        let local_var_error = ResponseContent {
1769            status: local_var_status,
1770            content: local_var_content,
1771            entity: local_var_entity,
1772            retry_delay: local_var_retry_delay,
1773        };
1774        Err(Error::ResponseError(local_var_error))
1775    }
1776}
1777
1778/// Get the onboarding status of the authenticated user.
1779pub async fn get_viewer_user_onboarding_completed(
1780    configuration: &configuration::Configuration,
1781) -> Result<
1782    crate::models::ViewerUserOnboardingCompleted,
1783    Error<GetViewerUserOnboardingCompletedError>,
1784> {
1785    let mut backoff = configuration.backoff.clone();
1786    let mut refreshed_credentials = false;
1787    let method = reqwest::Method::GET;
1788    loop {
1789        let result = get_viewer_user_onboarding_completed_inner(configuration, &mut backoff).await;
1790
1791        match result {
1792            Ok(result) => return Ok(result),
1793            Err(Error::ResponseError(response)) => {
1794                if !refreshed_credentials
1795                    && matches!(
1796                        response.status,
1797                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1798                    )
1799                {
1800                    configuration.qcs_config.refresh().await?;
1801                    refreshed_credentials = true;
1802                    continue;
1803                } else if let Some(duration) = response.retry_delay {
1804                    tokio::time::sleep(duration).await;
1805                    continue;
1806                }
1807
1808                return Err(Error::ResponseError(response));
1809            }
1810            Err(Error::Reqwest(error)) => {
1811                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1812                    tokio::time::sleep(duration).await;
1813                    continue;
1814                }
1815
1816                return Err(Error::Reqwest(error));
1817            }
1818            Err(Error::Io(error)) => {
1819                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1820                    tokio::time::sleep(duration).await;
1821                    continue;
1822                }
1823
1824                return Err(Error::Io(error));
1825            }
1826            Err(error) => return Err(error),
1827        }
1828    }
1829}
1830async fn list_group_billing_invoice_lines_inner(
1831    configuration: &configuration::Configuration,
1832    backoff: &mut ExponentialBackoff,
1833    group_name: &str,
1834    billing_invoice_id: &str,
1835    page_token: Option<&str>,
1836    page_size: Option<i64>,
1837) -> Result<
1838    crate::models::ListAccountBillingInvoiceLinesResponse,
1839    Error<ListGroupBillingInvoiceLinesError>,
1840> {
1841    let local_var_configuration = configuration;
1842
1843    let local_var_client = &local_var_configuration.client;
1844
1845    let local_var_uri_str = format!(
1846        "{}/v1/groups/{groupName}/billingInvoices/{billingInvoiceId}/lines",
1847        local_var_configuration.qcs_config.api_url(),
1848        groupName = crate::apis::urlencode(group_name),
1849        billingInvoiceId = crate::apis::urlencode(billing_invoice_id)
1850    );
1851    let mut local_var_req_builder =
1852        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1853
1854    #[cfg(feature = "tracing")]
1855    {
1856        // Ignore parsing errors if the URL is invalid for some reason.
1857        // If it is invalid, it will turn up as an error later when actually making the request.
1858        let local_var_do_tracing =
1859            local_var_uri_str
1860                .parse::<::url::Url>()
1861                .ok()
1862                .map_or(true, |url| {
1863                    configuration
1864                        .qcs_config
1865                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1866                });
1867
1868        if local_var_do_tracing {
1869            ::tracing::debug!(
1870                url=%local_var_uri_str,
1871                method="GET",
1872                "making list_group_billing_invoice_lines request",
1873            );
1874        }
1875    }
1876
1877    if let Some(ref local_var_str) = page_token {
1878        local_var_req_builder =
1879            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
1880    }
1881    if let Some(ref local_var_str) = page_size {
1882        local_var_req_builder =
1883            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
1884    }
1885
1886    // Use the QCS Bearer token if a client OAuthSession is present,
1887    // but do not require one when the security schema says it is optional.
1888    {
1889        use qcs_api_client_common::configuration::TokenError;
1890
1891        #[allow(
1892            clippy::nonminimal_bool,
1893            clippy::eq_op,
1894            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1895        )]
1896        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1897
1898        let token = local_var_configuration
1899            .qcs_config
1900            .get_bearer_access_token()
1901            .await;
1902
1903        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1904            // the client is configured without any OAuthSession, but this call does not require one.
1905            #[cfg(feature = "tracing")]
1906            tracing::debug!(
1907                "No client credentials found, but this call does not require authentication."
1908            );
1909        } else {
1910            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
1911        }
1912    }
1913
1914    let local_var_req = local_var_req_builder.build()?;
1915    let local_var_resp = local_var_client.execute(local_var_req).await?;
1916
1917    let local_var_status = local_var_resp.status();
1918
1919    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1920        let local_var_content = local_var_resp.text().await?;
1921        serde_json::from_str(&local_var_content).map_err(Error::from)
1922    } else {
1923        let local_var_retry_delay =
1924            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1925        let local_var_content = local_var_resp.text().await?;
1926        let local_var_entity: Option<ListGroupBillingInvoiceLinesError> =
1927            serde_json::from_str(&local_var_content).ok();
1928        let local_var_error = ResponseContent {
1929            status: local_var_status,
1930            content: local_var_content,
1931            entity: local_var_entity,
1932            retry_delay: local_var_retry_delay,
1933        };
1934        Err(Error::ResponseError(local_var_error))
1935    }
1936}
1937
1938/// Retrieve billing invoice lines for a QCS group account's invoice.
1939pub async fn list_group_billing_invoice_lines(
1940    configuration: &configuration::Configuration,
1941    group_name: &str,
1942    billing_invoice_id: &str,
1943    page_token: Option<&str>,
1944    page_size: Option<i64>,
1945) -> Result<
1946    crate::models::ListAccountBillingInvoiceLinesResponse,
1947    Error<ListGroupBillingInvoiceLinesError>,
1948> {
1949    let mut backoff = configuration.backoff.clone();
1950    let mut refreshed_credentials = false;
1951    let method = reqwest::Method::GET;
1952    loop {
1953        let result = list_group_billing_invoice_lines_inner(
1954            configuration,
1955            &mut backoff,
1956            group_name.clone(),
1957            billing_invoice_id.clone(),
1958            page_token.clone(),
1959            page_size.clone(),
1960        )
1961        .await;
1962
1963        match result {
1964            Ok(result) => return Ok(result),
1965            Err(Error::ResponseError(response)) => {
1966                if !refreshed_credentials
1967                    && matches!(
1968                        response.status,
1969                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1970                    )
1971                {
1972                    configuration.qcs_config.refresh().await?;
1973                    refreshed_credentials = true;
1974                    continue;
1975                } else if let Some(duration) = response.retry_delay {
1976                    tokio::time::sleep(duration).await;
1977                    continue;
1978                }
1979
1980                return Err(Error::ResponseError(response));
1981            }
1982            Err(Error::Reqwest(error)) => {
1983                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1984                    tokio::time::sleep(duration).await;
1985                    continue;
1986                }
1987
1988                return Err(Error::Reqwest(error));
1989            }
1990            Err(Error::Io(error)) => {
1991                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1992                    tokio::time::sleep(duration).await;
1993                    continue;
1994                }
1995
1996                return Err(Error::Io(error));
1997            }
1998            Err(error) => return Err(error),
1999        }
2000    }
2001}
2002async fn list_group_billing_invoices_inner(
2003    configuration: &configuration::Configuration,
2004    backoff: &mut ExponentialBackoff,
2005    group_name: &str,
2006    page_token: Option<&str>,
2007    page_size: Option<i64>,
2008) -> Result<crate::models::ListAccountBillingInvoicesResponse, Error<ListGroupBillingInvoicesError>>
2009{
2010    let local_var_configuration = configuration;
2011
2012    let local_var_client = &local_var_configuration.client;
2013
2014    let local_var_uri_str = format!(
2015        "{}/v1/groups/{groupName}/billingInvoices",
2016        local_var_configuration.qcs_config.api_url(),
2017        groupName = crate::apis::urlencode(group_name)
2018    );
2019    let mut local_var_req_builder =
2020        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
2021
2022    #[cfg(feature = "tracing")]
2023    {
2024        // Ignore parsing errors if the URL is invalid for some reason.
2025        // If it is invalid, it will turn up as an error later when actually making the request.
2026        let local_var_do_tracing =
2027            local_var_uri_str
2028                .parse::<::url::Url>()
2029                .ok()
2030                .map_or(true, |url| {
2031                    configuration
2032                        .qcs_config
2033                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
2034                });
2035
2036        if local_var_do_tracing {
2037            ::tracing::debug!(
2038                url=%local_var_uri_str,
2039                method="GET",
2040                "making list_group_billing_invoices request",
2041            );
2042        }
2043    }
2044
2045    if let Some(ref local_var_str) = page_token {
2046        local_var_req_builder =
2047            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
2048    }
2049    if let Some(ref local_var_str) = page_size {
2050        local_var_req_builder =
2051            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
2052    }
2053
2054    // Use the QCS Bearer token if a client OAuthSession is present,
2055    // but do not require one when the security schema says it is optional.
2056    {
2057        use qcs_api_client_common::configuration::TokenError;
2058
2059        #[allow(
2060            clippy::nonminimal_bool,
2061            clippy::eq_op,
2062            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
2063        )]
2064        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
2065
2066        let token = local_var_configuration
2067            .qcs_config
2068            .get_bearer_access_token()
2069            .await;
2070
2071        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
2072            // the client is configured without any OAuthSession, but this call does not require one.
2073            #[cfg(feature = "tracing")]
2074            tracing::debug!(
2075                "No client credentials found, but this call does not require authentication."
2076            );
2077        } else {
2078            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
2079        }
2080    }
2081
2082    let local_var_req = local_var_req_builder.build()?;
2083    let local_var_resp = local_var_client.execute(local_var_req).await?;
2084
2085    let local_var_status = local_var_resp.status();
2086
2087    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
2088        let local_var_content = local_var_resp.text().await?;
2089        serde_json::from_str(&local_var_content).map_err(Error::from)
2090    } else {
2091        let local_var_retry_delay =
2092            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
2093        let local_var_content = local_var_resp.text().await?;
2094        let local_var_entity: Option<ListGroupBillingInvoicesError> =
2095            serde_json::from_str(&local_var_content).ok();
2096        let local_var_error = ResponseContent {
2097            status: local_var_status,
2098            content: local_var_content,
2099            entity: local_var_entity,
2100            retry_delay: local_var_retry_delay,
2101        };
2102        Err(Error::ResponseError(local_var_error))
2103    }
2104}
2105
2106/// Retrieve billing invoices for a QCS group account.
2107pub async fn list_group_billing_invoices(
2108    configuration: &configuration::Configuration,
2109    group_name: &str,
2110    page_token: Option<&str>,
2111    page_size: Option<i64>,
2112) -> Result<crate::models::ListAccountBillingInvoicesResponse, Error<ListGroupBillingInvoicesError>>
2113{
2114    let mut backoff = configuration.backoff.clone();
2115    let mut refreshed_credentials = false;
2116    let method = reqwest::Method::GET;
2117    loop {
2118        let result = list_group_billing_invoices_inner(
2119            configuration,
2120            &mut backoff,
2121            group_name.clone(),
2122            page_token.clone(),
2123            page_size.clone(),
2124        )
2125        .await;
2126
2127        match result {
2128            Ok(result) => return Ok(result),
2129            Err(Error::ResponseError(response)) => {
2130                if !refreshed_credentials
2131                    && matches!(
2132                        response.status,
2133                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
2134                    )
2135                {
2136                    configuration.qcs_config.refresh().await?;
2137                    refreshed_credentials = true;
2138                    continue;
2139                } else if let Some(duration) = response.retry_delay {
2140                    tokio::time::sleep(duration).await;
2141                    continue;
2142                }
2143
2144                return Err(Error::ResponseError(response));
2145            }
2146            Err(Error::Reqwest(error)) => {
2147                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
2148                    tokio::time::sleep(duration).await;
2149                    continue;
2150                }
2151
2152                return Err(Error::Reqwest(error));
2153            }
2154            Err(Error::Io(error)) => {
2155                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
2156                    tokio::time::sleep(duration).await;
2157                    continue;
2158                }
2159
2160                return Err(Error::Io(error));
2161            }
2162            Err(error) => return Err(error),
2163        }
2164    }
2165}
2166async fn list_group_upcoming_billing_invoice_lines_inner(
2167    configuration: &configuration::Configuration,
2168    backoff: &mut ExponentialBackoff,
2169    group_name: &str,
2170    page_token: Option<&str>,
2171    page_size: Option<i64>,
2172) -> Result<
2173    crate::models::ListAccountBillingInvoiceLinesResponse,
2174    Error<ListGroupUpcomingBillingInvoiceLinesError>,
2175> {
2176    let local_var_configuration = configuration;
2177
2178    let local_var_client = &local_var_configuration.client;
2179
2180    let local_var_uri_str = format!(
2181        "{}/v1/groups/{groupName}/billingInvoices:listUpcomingLines",
2182        local_var_configuration.qcs_config.api_url(),
2183        groupName = crate::apis::urlencode(group_name)
2184    );
2185    let mut local_var_req_builder =
2186        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
2187
2188    #[cfg(feature = "tracing")]
2189    {
2190        // Ignore parsing errors if the URL is invalid for some reason.
2191        // If it is invalid, it will turn up as an error later when actually making the request.
2192        let local_var_do_tracing =
2193            local_var_uri_str
2194                .parse::<::url::Url>()
2195                .ok()
2196                .map_or(true, |url| {
2197                    configuration
2198                        .qcs_config
2199                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
2200                });
2201
2202        if local_var_do_tracing {
2203            ::tracing::debug!(
2204                url=%local_var_uri_str,
2205                method="GET",
2206                "making list_group_upcoming_billing_invoice_lines request",
2207            );
2208        }
2209    }
2210
2211    if let Some(ref local_var_str) = page_token {
2212        local_var_req_builder =
2213            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
2214    }
2215    if let Some(ref local_var_str) = page_size {
2216        local_var_req_builder =
2217            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
2218    }
2219
2220    // Use the QCS Bearer token if a client OAuthSession is present,
2221    // but do not require one when the security schema says it is optional.
2222    {
2223        use qcs_api_client_common::configuration::TokenError;
2224
2225        #[allow(
2226            clippy::nonminimal_bool,
2227            clippy::eq_op,
2228            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
2229        )]
2230        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
2231
2232        let token = local_var_configuration
2233            .qcs_config
2234            .get_bearer_access_token()
2235            .await;
2236
2237        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
2238            // the client is configured without any OAuthSession, but this call does not require one.
2239            #[cfg(feature = "tracing")]
2240            tracing::debug!(
2241                "No client credentials found, but this call does not require authentication."
2242            );
2243        } else {
2244            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
2245        }
2246    }
2247
2248    let local_var_req = local_var_req_builder.build()?;
2249    let local_var_resp = local_var_client.execute(local_var_req).await?;
2250
2251    let local_var_status = local_var_resp.status();
2252
2253    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
2254        let local_var_content = local_var_resp.text().await?;
2255        serde_json::from_str(&local_var_content).map_err(Error::from)
2256    } else {
2257        let local_var_retry_delay =
2258            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
2259        let local_var_content = local_var_resp.text().await?;
2260        let local_var_entity: Option<ListGroupUpcomingBillingInvoiceLinesError> =
2261            serde_json::from_str(&local_var_content).ok();
2262        let local_var_error = ResponseContent {
2263            status: local_var_status,
2264            content: local_var_content,
2265            entity: local_var_entity,
2266            retry_delay: local_var_retry_delay,
2267        };
2268        Err(Error::ResponseError(local_var_error))
2269    }
2270}
2271
2272/// List invoice lines for QCS group billing customer upcoming invoice.
2273pub async fn list_group_upcoming_billing_invoice_lines(
2274    configuration: &configuration::Configuration,
2275    group_name: &str,
2276    page_token: Option<&str>,
2277    page_size: Option<i64>,
2278) -> Result<
2279    crate::models::ListAccountBillingInvoiceLinesResponse,
2280    Error<ListGroupUpcomingBillingInvoiceLinesError>,
2281> {
2282    let mut backoff = configuration.backoff.clone();
2283    let mut refreshed_credentials = false;
2284    let method = reqwest::Method::GET;
2285    loop {
2286        let result = list_group_upcoming_billing_invoice_lines_inner(
2287            configuration,
2288            &mut backoff,
2289            group_name.clone(),
2290            page_token.clone(),
2291            page_size.clone(),
2292        )
2293        .await;
2294
2295        match result {
2296            Ok(result) => return Ok(result),
2297            Err(Error::ResponseError(response)) => {
2298                if !refreshed_credentials
2299                    && matches!(
2300                        response.status,
2301                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
2302                    )
2303                {
2304                    configuration.qcs_config.refresh().await?;
2305                    refreshed_credentials = true;
2306                    continue;
2307                } else if let Some(duration) = response.retry_delay {
2308                    tokio::time::sleep(duration).await;
2309                    continue;
2310                }
2311
2312                return Err(Error::ResponseError(response));
2313            }
2314            Err(Error::Reqwest(error)) => {
2315                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
2316                    tokio::time::sleep(duration).await;
2317                    continue;
2318                }
2319
2320                return Err(Error::Reqwest(error));
2321            }
2322            Err(Error::Io(error)) => {
2323                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
2324                    tokio::time::sleep(duration).await;
2325                    continue;
2326                }
2327
2328                return Err(Error::Io(error));
2329            }
2330            Err(error) => return Err(error),
2331        }
2332    }
2333}
2334async fn list_group_users_inner(
2335    configuration: &configuration::Configuration,
2336    backoff: &mut ExponentialBackoff,
2337    group_name: &str,
2338    page_size: Option<i64>,
2339    page_token: Option<&str>,
2340) -> Result<crate::models::ListGroupUsersResponse, Error<ListGroupUsersError>> {
2341    let local_var_configuration = configuration;
2342
2343    let local_var_client = &local_var_configuration.client;
2344
2345    let local_var_uri_str = format!(
2346        "{}/v1/groups/{groupName}/users",
2347        local_var_configuration.qcs_config.api_url(),
2348        groupName = crate::apis::urlencode(group_name)
2349    );
2350    let mut local_var_req_builder =
2351        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
2352
2353    #[cfg(feature = "tracing")]
2354    {
2355        // Ignore parsing errors if the URL is invalid for some reason.
2356        // If it is invalid, it will turn up as an error later when actually making the request.
2357        let local_var_do_tracing =
2358            local_var_uri_str
2359                .parse::<::url::Url>()
2360                .ok()
2361                .map_or(true, |url| {
2362                    configuration
2363                        .qcs_config
2364                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
2365                });
2366
2367        if local_var_do_tracing {
2368            ::tracing::debug!(
2369                url=%local_var_uri_str,
2370                method="GET",
2371                "making list_group_users request",
2372            );
2373        }
2374    }
2375
2376    if let Some(ref local_var_str) = page_size {
2377        local_var_req_builder =
2378            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
2379    }
2380    if let Some(ref local_var_str) = page_token {
2381        local_var_req_builder =
2382            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
2383    }
2384
2385    // Use the QCS Bearer token if a client OAuthSession is present,
2386    // but do not require one when the security schema says it is optional.
2387    {
2388        use qcs_api_client_common::configuration::TokenError;
2389
2390        #[allow(
2391            clippy::nonminimal_bool,
2392            clippy::eq_op,
2393            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
2394        )]
2395        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
2396
2397        let token = local_var_configuration
2398            .qcs_config
2399            .get_bearer_access_token()
2400            .await;
2401
2402        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
2403            // the client is configured without any OAuthSession, but this call does not require one.
2404            #[cfg(feature = "tracing")]
2405            tracing::debug!(
2406                "No client credentials found, but this call does not require authentication."
2407            );
2408        } else {
2409            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
2410        }
2411    }
2412
2413    let local_var_req = local_var_req_builder.build()?;
2414    let local_var_resp = local_var_client.execute(local_var_req).await?;
2415
2416    let local_var_status = local_var_resp.status();
2417
2418    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
2419        let local_var_content = local_var_resp.text().await?;
2420        serde_json::from_str(&local_var_content).map_err(Error::from)
2421    } else {
2422        let local_var_retry_delay =
2423            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
2424        let local_var_content = local_var_resp.text().await?;
2425        let local_var_entity: Option<ListGroupUsersError> =
2426            serde_json::from_str(&local_var_content).ok();
2427        let local_var_error = ResponseContent {
2428            status: local_var_status,
2429            content: local_var_content,
2430            entity: local_var_entity,
2431            retry_delay: local_var_retry_delay,
2432        };
2433        Err(Error::ResponseError(local_var_error))
2434    }
2435}
2436
2437/// List users belonging to a group. Note, group membership may take several minutes to update within our identity provider. After adding or removing a user to or from a group, please allow up to 60 minutes for changes to be reflected.
2438pub async fn list_group_users(
2439    configuration: &configuration::Configuration,
2440    group_name: &str,
2441    page_size: Option<i64>,
2442    page_token: Option<&str>,
2443) -> Result<crate::models::ListGroupUsersResponse, Error<ListGroupUsersError>> {
2444    let mut backoff = configuration.backoff.clone();
2445    let mut refreshed_credentials = false;
2446    let method = reqwest::Method::GET;
2447    loop {
2448        let result = list_group_users_inner(
2449            configuration,
2450            &mut backoff,
2451            group_name.clone(),
2452            page_size.clone(),
2453            page_token.clone(),
2454        )
2455        .await;
2456
2457        match result {
2458            Ok(result) => return Ok(result),
2459            Err(Error::ResponseError(response)) => {
2460                if !refreshed_credentials
2461                    && matches!(
2462                        response.status,
2463                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
2464                    )
2465                {
2466                    configuration.qcs_config.refresh().await?;
2467                    refreshed_credentials = true;
2468                    continue;
2469                } else if let Some(duration) = response.retry_delay {
2470                    tokio::time::sleep(duration).await;
2471                    continue;
2472                }
2473
2474                return Err(Error::ResponseError(response));
2475            }
2476            Err(Error::Reqwest(error)) => {
2477                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
2478                    tokio::time::sleep(duration).await;
2479                    continue;
2480                }
2481
2482                return Err(Error::Reqwest(error));
2483            }
2484            Err(Error::Io(error)) => {
2485                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
2486                    tokio::time::sleep(duration).await;
2487                    continue;
2488                }
2489
2490                return Err(Error::Io(error));
2491            }
2492            Err(error) => return Err(error),
2493        }
2494    }
2495}
2496async fn list_user_billing_invoice_lines_inner(
2497    configuration: &configuration::Configuration,
2498    backoff: &mut ExponentialBackoff,
2499    user_id: &str,
2500    billing_invoice_id: &str,
2501    page_token: Option<&str>,
2502    page_size: Option<i64>,
2503) -> Result<
2504    crate::models::ListAccountBillingInvoiceLinesResponse,
2505    Error<ListUserBillingInvoiceLinesError>,
2506> {
2507    let local_var_configuration = configuration;
2508
2509    let local_var_client = &local_var_configuration.client;
2510
2511    let local_var_uri_str = format!(
2512        "{}/v1/users/{userId}/billingInvoices/{billingInvoiceId}/lines",
2513        local_var_configuration.qcs_config.api_url(),
2514        userId = crate::apis::urlencode(user_id),
2515        billingInvoiceId = crate::apis::urlencode(billing_invoice_id)
2516    );
2517    let mut local_var_req_builder =
2518        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
2519
2520    #[cfg(feature = "tracing")]
2521    {
2522        // Ignore parsing errors if the URL is invalid for some reason.
2523        // If it is invalid, it will turn up as an error later when actually making the request.
2524        let local_var_do_tracing =
2525            local_var_uri_str
2526                .parse::<::url::Url>()
2527                .ok()
2528                .map_or(true, |url| {
2529                    configuration
2530                        .qcs_config
2531                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
2532                });
2533
2534        if local_var_do_tracing {
2535            ::tracing::debug!(
2536                url=%local_var_uri_str,
2537                method="GET",
2538                "making list_user_billing_invoice_lines request",
2539            );
2540        }
2541    }
2542
2543    if let Some(ref local_var_str) = page_token {
2544        local_var_req_builder =
2545            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
2546    }
2547    if let Some(ref local_var_str) = page_size {
2548        local_var_req_builder =
2549            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
2550    }
2551
2552    // Use the QCS Bearer token if a client OAuthSession is present,
2553    // but do not require one when the security schema says it is optional.
2554    {
2555        use qcs_api_client_common::configuration::TokenError;
2556
2557        #[allow(
2558            clippy::nonminimal_bool,
2559            clippy::eq_op,
2560            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
2561        )]
2562        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
2563
2564        let token = local_var_configuration
2565            .qcs_config
2566            .get_bearer_access_token()
2567            .await;
2568
2569        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
2570            // the client is configured without any OAuthSession, but this call does not require one.
2571            #[cfg(feature = "tracing")]
2572            tracing::debug!(
2573                "No client credentials found, but this call does not require authentication."
2574            );
2575        } else {
2576            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
2577        }
2578    }
2579
2580    let local_var_req = local_var_req_builder.build()?;
2581    let local_var_resp = local_var_client.execute(local_var_req).await?;
2582
2583    let local_var_status = local_var_resp.status();
2584
2585    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
2586        let local_var_content = local_var_resp.text().await?;
2587        serde_json::from_str(&local_var_content).map_err(Error::from)
2588    } else {
2589        let local_var_retry_delay =
2590            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
2591        let local_var_content = local_var_resp.text().await?;
2592        let local_var_entity: Option<ListUserBillingInvoiceLinesError> =
2593            serde_json::from_str(&local_var_content).ok();
2594        let local_var_error = ResponseContent {
2595            status: local_var_status,
2596            content: local_var_content,
2597            entity: local_var_entity,
2598            retry_delay: local_var_retry_delay,
2599        };
2600        Err(Error::ResponseError(local_var_error))
2601    }
2602}
2603
2604/// Retrieve billing invoice lines for a QCS user account's invoice.
2605pub async fn list_user_billing_invoice_lines(
2606    configuration: &configuration::Configuration,
2607    user_id: &str,
2608    billing_invoice_id: &str,
2609    page_token: Option<&str>,
2610    page_size: Option<i64>,
2611) -> Result<
2612    crate::models::ListAccountBillingInvoiceLinesResponse,
2613    Error<ListUserBillingInvoiceLinesError>,
2614> {
2615    let mut backoff = configuration.backoff.clone();
2616    let mut refreshed_credentials = false;
2617    let method = reqwest::Method::GET;
2618    loop {
2619        let result = list_user_billing_invoice_lines_inner(
2620            configuration,
2621            &mut backoff,
2622            user_id.clone(),
2623            billing_invoice_id.clone(),
2624            page_token.clone(),
2625            page_size.clone(),
2626        )
2627        .await;
2628
2629        match result {
2630            Ok(result) => return Ok(result),
2631            Err(Error::ResponseError(response)) => {
2632                if !refreshed_credentials
2633                    && matches!(
2634                        response.status,
2635                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
2636                    )
2637                {
2638                    configuration.qcs_config.refresh().await?;
2639                    refreshed_credentials = true;
2640                    continue;
2641                } else if let Some(duration) = response.retry_delay {
2642                    tokio::time::sleep(duration).await;
2643                    continue;
2644                }
2645
2646                return Err(Error::ResponseError(response));
2647            }
2648            Err(Error::Reqwest(error)) => {
2649                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
2650                    tokio::time::sleep(duration).await;
2651                    continue;
2652                }
2653
2654                return Err(Error::Reqwest(error));
2655            }
2656            Err(Error::Io(error)) => {
2657                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
2658                    tokio::time::sleep(duration).await;
2659                    continue;
2660                }
2661
2662                return Err(Error::Io(error));
2663            }
2664            Err(error) => return Err(error),
2665        }
2666    }
2667}
2668async fn list_user_billing_invoices_inner(
2669    configuration: &configuration::Configuration,
2670    backoff: &mut ExponentialBackoff,
2671    user_id: &str,
2672    page_token: Option<&str>,
2673    page_size: Option<i64>,
2674) -> Result<crate::models::ListAccountBillingInvoicesResponse, Error<ListUserBillingInvoicesError>>
2675{
2676    let local_var_configuration = configuration;
2677
2678    let local_var_client = &local_var_configuration.client;
2679
2680    let local_var_uri_str = format!(
2681        "{}/v1/users/{userId}/billingInvoices",
2682        local_var_configuration.qcs_config.api_url(),
2683        userId = crate::apis::urlencode(user_id)
2684    );
2685    let mut local_var_req_builder =
2686        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
2687
2688    #[cfg(feature = "tracing")]
2689    {
2690        // Ignore parsing errors if the URL is invalid for some reason.
2691        // If it is invalid, it will turn up as an error later when actually making the request.
2692        let local_var_do_tracing =
2693            local_var_uri_str
2694                .parse::<::url::Url>()
2695                .ok()
2696                .map_or(true, |url| {
2697                    configuration
2698                        .qcs_config
2699                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
2700                });
2701
2702        if local_var_do_tracing {
2703            ::tracing::debug!(
2704                url=%local_var_uri_str,
2705                method="GET",
2706                "making list_user_billing_invoices request",
2707            );
2708        }
2709    }
2710
2711    if let Some(ref local_var_str) = page_token {
2712        local_var_req_builder =
2713            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
2714    }
2715    if let Some(ref local_var_str) = page_size {
2716        local_var_req_builder =
2717            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
2718    }
2719
2720    // Use the QCS Bearer token if a client OAuthSession is present,
2721    // but do not require one when the security schema says it is optional.
2722    {
2723        use qcs_api_client_common::configuration::TokenError;
2724
2725        #[allow(
2726            clippy::nonminimal_bool,
2727            clippy::eq_op,
2728            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
2729        )]
2730        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
2731
2732        let token = local_var_configuration
2733            .qcs_config
2734            .get_bearer_access_token()
2735            .await;
2736
2737        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
2738            // the client is configured without any OAuthSession, but this call does not require one.
2739            #[cfg(feature = "tracing")]
2740            tracing::debug!(
2741                "No client credentials found, but this call does not require authentication."
2742            );
2743        } else {
2744            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
2745        }
2746    }
2747
2748    let local_var_req = local_var_req_builder.build()?;
2749    let local_var_resp = local_var_client.execute(local_var_req).await?;
2750
2751    let local_var_status = local_var_resp.status();
2752
2753    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
2754        let local_var_content = local_var_resp.text().await?;
2755        serde_json::from_str(&local_var_content).map_err(Error::from)
2756    } else {
2757        let local_var_retry_delay =
2758            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
2759        let local_var_content = local_var_resp.text().await?;
2760        let local_var_entity: Option<ListUserBillingInvoicesError> =
2761            serde_json::from_str(&local_var_content).ok();
2762        let local_var_error = ResponseContent {
2763            status: local_var_status,
2764            content: local_var_content,
2765            entity: local_var_entity,
2766            retry_delay: local_var_retry_delay,
2767        };
2768        Err(Error::ResponseError(local_var_error))
2769    }
2770}
2771
2772/// Retrieve billing invoices for a QCS user account.
2773pub async fn list_user_billing_invoices(
2774    configuration: &configuration::Configuration,
2775    user_id: &str,
2776    page_token: Option<&str>,
2777    page_size: Option<i64>,
2778) -> Result<crate::models::ListAccountBillingInvoicesResponse, Error<ListUserBillingInvoicesError>>
2779{
2780    let mut backoff = configuration.backoff.clone();
2781    let mut refreshed_credentials = false;
2782    let method = reqwest::Method::GET;
2783    loop {
2784        let result = list_user_billing_invoices_inner(
2785            configuration,
2786            &mut backoff,
2787            user_id.clone(),
2788            page_token.clone(),
2789            page_size.clone(),
2790        )
2791        .await;
2792
2793        match result {
2794            Ok(result) => return Ok(result),
2795            Err(Error::ResponseError(response)) => {
2796                if !refreshed_credentials
2797                    && matches!(
2798                        response.status,
2799                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
2800                    )
2801                {
2802                    configuration.qcs_config.refresh().await?;
2803                    refreshed_credentials = true;
2804                    continue;
2805                } else if let Some(duration) = response.retry_delay {
2806                    tokio::time::sleep(duration).await;
2807                    continue;
2808                }
2809
2810                return Err(Error::ResponseError(response));
2811            }
2812            Err(Error::Reqwest(error)) => {
2813                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
2814                    tokio::time::sleep(duration).await;
2815                    continue;
2816                }
2817
2818                return Err(Error::Reqwest(error));
2819            }
2820            Err(Error::Io(error)) => {
2821                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
2822                    tokio::time::sleep(duration).await;
2823                    continue;
2824                }
2825
2826                return Err(Error::Io(error));
2827            }
2828            Err(error) => return Err(error),
2829        }
2830    }
2831}
2832async fn list_user_groups_inner(
2833    configuration: &configuration::Configuration,
2834    backoff: &mut ExponentialBackoff,
2835    user_id: &str,
2836    page_size: Option<i64>,
2837    page_token: Option<&str>,
2838) -> Result<crate::models::ListGroupsResponse, Error<ListUserGroupsError>> {
2839    let local_var_configuration = configuration;
2840
2841    let local_var_client = &local_var_configuration.client;
2842
2843    let local_var_uri_str = format!(
2844        "{}/v1/users/{userId}/groups",
2845        local_var_configuration.qcs_config.api_url(),
2846        userId = crate::apis::urlencode(user_id)
2847    );
2848    let mut local_var_req_builder =
2849        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
2850
2851    #[cfg(feature = "tracing")]
2852    {
2853        // Ignore parsing errors if the URL is invalid for some reason.
2854        // If it is invalid, it will turn up as an error later when actually making the request.
2855        let local_var_do_tracing =
2856            local_var_uri_str
2857                .parse::<::url::Url>()
2858                .ok()
2859                .map_or(true, |url| {
2860                    configuration
2861                        .qcs_config
2862                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
2863                });
2864
2865        if local_var_do_tracing {
2866            ::tracing::debug!(
2867                url=%local_var_uri_str,
2868                method="GET",
2869                "making list_user_groups request",
2870            );
2871        }
2872    }
2873
2874    if let Some(ref local_var_str) = page_size {
2875        local_var_req_builder =
2876            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
2877    }
2878    if let Some(ref local_var_str) = page_token {
2879        local_var_req_builder =
2880            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
2881    }
2882
2883    // Use the QCS Bearer token if a client OAuthSession is present,
2884    // but do not require one when the security schema says it is optional.
2885    {
2886        use qcs_api_client_common::configuration::TokenError;
2887
2888        #[allow(
2889            clippy::nonminimal_bool,
2890            clippy::eq_op,
2891            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
2892        )]
2893        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
2894
2895        let token = local_var_configuration
2896            .qcs_config
2897            .get_bearer_access_token()
2898            .await;
2899
2900        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
2901            // the client is configured without any OAuthSession, but this call does not require one.
2902            #[cfg(feature = "tracing")]
2903            tracing::debug!(
2904                "No client credentials found, but this call does not require authentication."
2905            );
2906        } else {
2907            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
2908        }
2909    }
2910
2911    let local_var_req = local_var_req_builder.build()?;
2912    let local_var_resp = local_var_client.execute(local_var_req).await?;
2913
2914    let local_var_status = local_var_resp.status();
2915
2916    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
2917        let local_var_content = local_var_resp.text().await?;
2918        serde_json::from_str(&local_var_content).map_err(Error::from)
2919    } else {
2920        let local_var_retry_delay =
2921            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
2922        let local_var_content = local_var_resp.text().await?;
2923        let local_var_entity: Option<ListUserGroupsError> =
2924            serde_json::from_str(&local_var_content).ok();
2925        let local_var_error = ResponseContent {
2926            status: local_var_status,
2927            content: local_var_content,
2928            entity: local_var_entity,
2929            retry_delay: local_var_retry_delay,
2930        };
2931        Err(Error::ResponseError(local_var_error))
2932    }
2933}
2934
2935/// List QCS groups for the requested user
2936pub async fn list_user_groups(
2937    configuration: &configuration::Configuration,
2938    user_id: &str,
2939    page_size: Option<i64>,
2940    page_token: Option<&str>,
2941) -> Result<crate::models::ListGroupsResponse, Error<ListUserGroupsError>> {
2942    let mut backoff = configuration.backoff.clone();
2943    let mut refreshed_credentials = false;
2944    let method = reqwest::Method::GET;
2945    loop {
2946        let result = list_user_groups_inner(
2947            configuration,
2948            &mut backoff,
2949            user_id.clone(),
2950            page_size.clone(),
2951            page_token.clone(),
2952        )
2953        .await;
2954
2955        match result {
2956            Ok(result) => return Ok(result),
2957            Err(Error::ResponseError(response)) => {
2958                if !refreshed_credentials
2959                    && matches!(
2960                        response.status,
2961                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
2962                    )
2963                {
2964                    configuration.qcs_config.refresh().await?;
2965                    refreshed_credentials = true;
2966                    continue;
2967                } else if let Some(duration) = response.retry_delay {
2968                    tokio::time::sleep(duration).await;
2969                    continue;
2970                }
2971
2972                return Err(Error::ResponseError(response));
2973            }
2974            Err(Error::Reqwest(error)) => {
2975                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
2976                    tokio::time::sleep(duration).await;
2977                    continue;
2978                }
2979
2980                return Err(Error::Reqwest(error));
2981            }
2982            Err(Error::Io(error)) => {
2983                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
2984                    tokio::time::sleep(duration).await;
2985                    continue;
2986                }
2987
2988                return Err(Error::Io(error));
2989            }
2990            Err(error) => return Err(error),
2991        }
2992    }
2993}
2994async fn list_user_upcoming_billing_invoice_lines_inner(
2995    configuration: &configuration::Configuration,
2996    backoff: &mut ExponentialBackoff,
2997    user_id: &str,
2998    page_token: Option<&str>,
2999    page_size: Option<i64>,
3000) -> Result<
3001    crate::models::ListAccountBillingInvoiceLinesResponse,
3002    Error<ListUserUpcomingBillingInvoiceLinesError>,
3003> {
3004    let local_var_configuration = configuration;
3005
3006    let local_var_client = &local_var_configuration.client;
3007
3008    let local_var_uri_str = format!(
3009        "{}/v1/users/{userId}/billingInvoices:listUpcomingLines",
3010        local_var_configuration.qcs_config.api_url(),
3011        userId = crate::apis::urlencode(user_id)
3012    );
3013    let mut local_var_req_builder =
3014        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
3015
3016    #[cfg(feature = "tracing")]
3017    {
3018        // Ignore parsing errors if the URL is invalid for some reason.
3019        // If it is invalid, it will turn up as an error later when actually making the request.
3020        let local_var_do_tracing =
3021            local_var_uri_str
3022                .parse::<::url::Url>()
3023                .ok()
3024                .map_or(true, |url| {
3025                    configuration
3026                        .qcs_config
3027                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
3028                });
3029
3030        if local_var_do_tracing {
3031            ::tracing::debug!(
3032                url=%local_var_uri_str,
3033                method="GET",
3034                "making list_user_upcoming_billing_invoice_lines request",
3035            );
3036        }
3037    }
3038
3039    if let Some(ref local_var_str) = page_token {
3040        local_var_req_builder =
3041            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
3042    }
3043    if let Some(ref local_var_str) = page_size {
3044        local_var_req_builder =
3045            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
3046    }
3047
3048    // Use the QCS Bearer token if a client OAuthSession is present,
3049    // but do not require one when the security schema says it is optional.
3050    {
3051        use qcs_api_client_common::configuration::TokenError;
3052
3053        #[allow(
3054            clippy::nonminimal_bool,
3055            clippy::eq_op,
3056            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
3057        )]
3058        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
3059
3060        let token = local_var_configuration
3061            .qcs_config
3062            .get_bearer_access_token()
3063            .await;
3064
3065        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
3066            // the client is configured without any OAuthSession, but this call does not require one.
3067            #[cfg(feature = "tracing")]
3068            tracing::debug!(
3069                "No client credentials found, but this call does not require authentication."
3070            );
3071        } else {
3072            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
3073        }
3074    }
3075
3076    let local_var_req = local_var_req_builder.build()?;
3077    let local_var_resp = local_var_client.execute(local_var_req).await?;
3078
3079    let local_var_status = local_var_resp.status();
3080
3081    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
3082        let local_var_content = local_var_resp.text().await?;
3083        serde_json::from_str(&local_var_content).map_err(Error::from)
3084    } else {
3085        let local_var_retry_delay =
3086            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
3087        let local_var_content = local_var_resp.text().await?;
3088        let local_var_entity: Option<ListUserUpcomingBillingInvoiceLinesError> =
3089            serde_json::from_str(&local_var_content).ok();
3090        let local_var_error = ResponseContent {
3091            status: local_var_status,
3092            content: local_var_content,
3093            entity: local_var_entity,
3094            retry_delay: local_var_retry_delay,
3095        };
3096        Err(Error::ResponseError(local_var_error))
3097    }
3098}
3099
3100/// List invoice lines for QCS user billing customer upcoming invoice.
3101pub async fn list_user_upcoming_billing_invoice_lines(
3102    configuration: &configuration::Configuration,
3103    user_id: &str,
3104    page_token: Option<&str>,
3105    page_size: Option<i64>,
3106) -> Result<
3107    crate::models::ListAccountBillingInvoiceLinesResponse,
3108    Error<ListUserUpcomingBillingInvoiceLinesError>,
3109> {
3110    let mut backoff = configuration.backoff.clone();
3111    let mut refreshed_credentials = false;
3112    let method = reqwest::Method::GET;
3113    loop {
3114        let result = list_user_upcoming_billing_invoice_lines_inner(
3115            configuration,
3116            &mut backoff,
3117            user_id.clone(),
3118            page_token.clone(),
3119            page_size.clone(),
3120        )
3121        .await;
3122
3123        match result {
3124            Ok(result) => return Ok(result),
3125            Err(Error::ResponseError(response)) => {
3126                if !refreshed_credentials
3127                    && matches!(
3128                        response.status,
3129                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
3130                    )
3131                {
3132                    configuration.qcs_config.refresh().await?;
3133                    refreshed_credentials = true;
3134                    continue;
3135                } else if let Some(duration) = response.retry_delay {
3136                    tokio::time::sleep(duration).await;
3137                    continue;
3138                }
3139
3140                return Err(Error::ResponseError(response));
3141            }
3142            Err(Error::Reqwest(error)) => {
3143                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
3144                    tokio::time::sleep(duration).await;
3145                    continue;
3146                }
3147
3148                return Err(Error::Reqwest(error));
3149            }
3150            Err(Error::Io(error)) => {
3151                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
3152                    tokio::time::sleep(duration).await;
3153                    continue;
3154                }
3155
3156                return Err(Error::Io(error));
3157            }
3158            Err(error) => return Err(error),
3159        }
3160    }
3161}
3162async fn list_viewer_announcements_inner(
3163    configuration: &configuration::Configuration,
3164    backoff: &mut ExponentialBackoff,
3165    page_size: Option<i64>,
3166    page_token: Option<&str>,
3167    include_dismissed: Option<bool>,
3168) -> Result<crate::models::AnnouncementsResponse, Error<ListViewerAnnouncementsError>> {
3169    let local_var_configuration = configuration;
3170
3171    let local_var_client = &local_var_configuration.client;
3172
3173    let local_var_uri_str = format!(
3174        "{}/v1/viewer/announcements",
3175        local_var_configuration.qcs_config.api_url()
3176    );
3177    let mut local_var_req_builder =
3178        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
3179
3180    #[cfg(feature = "tracing")]
3181    {
3182        // Ignore parsing errors if the URL is invalid for some reason.
3183        // If it is invalid, it will turn up as an error later when actually making the request.
3184        let local_var_do_tracing =
3185            local_var_uri_str
3186                .parse::<::url::Url>()
3187                .ok()
3188                .map_or(true, |url| {
3189                    configuration
3190                        .qcs_config
3191                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
3192                });
3193
3194        if local_var_do_tracing {
3195            ::tracing::debug!(
3196                url=%local_var_uri_str,
3197                method="GET",
3198                "making list_viewer_announcements request",
3199            );
3200        }
3201    }
3202
3203    if let Some(ref local_var_str) = page_size {
3204        local_var_req_builder =
3205            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
3206    }
3207    if let Some(ref local_var_str) = page_token {
3208        local_var_req_builder =
3209            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
3210    }
3211    if let Some(ref local_var_str) = include_dismissed {
3212        local_var_req_builder =
3213            local_var_req_builder.query(&[("includeDismissed", &local_var_str.to_string())]);
3214    }
3215
3216    // Use the QCS Bearer token if a client OAuthSession is present,
3217    // but do not require one when the security schema says it is optional.
3218    {
3219        use qcs_api_client_common::configuration::TokenError;
3220
3221        #[allow(
3222            clippy::nonminimal_bool,
3223            clippy::eq_op,
3224            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
3225        )]
3226        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
3227
3228        let token = local_var_configuration
3229            .qcs_config
3230            .get_bearer_access_token()
3231            .await;
3232
3233        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
3234            // the client is configured without any OAuthSession, but this call does not require one.
3235            #[cfg(feature = "tracing")]
3236            tracing::debug!(
3237                "No client credentials found, but this call does not require authentication."
3238            );
3239        } else {
3240            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
3241        }
3242    }
3243
3244    let local_var_req = local_var_req_builder.build()?;
3245    let local_var_resp = local_var_client.execute(local_var_req).await?;
3246
3247    let local_var_status = local_var_resp.status();
3248
3249    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
3250        let local_var_content = local_var_resp.text().await?;
3251        serde_json::from_str(&local_var_content).map_err(Error::from)
3252    } else {
3253        let local_var_retry_delay =
3254            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
3255        let local_var_content = local_var_resp.text().await?;
3256        let local_var_entity: Option<ListViewerAnnouncementsError> =
3257            serde_json::from_str(&local_var_content).ok();
3258        let local_var_error = ResponseContent {
3259            status: local_var_status,
3260            content: local_var_content,
3261            entity: local_var_entity,
3262            retry_delay: local_var_retry_delay,
3263        };
3264        Err(Error::ResponseError(local_var_error))
3265    }
3266}
3267
3268/// List all announcements relevant to the authenticating user. By default, does not include dismissed announcements.
3269pub async fn list_viewer_announcements(
3270    configuration: &configuration::Configuration,
3271    page_size: Option<i64>,
3272    page_token: Option<&str>,
3273    include_dismissed: Option<bool>,
3274) -> Result<crate::models::AnnouncementsResponse, Error<ListViewerAnnouncementsError>> {
3275    let mut backoff = configuration.backoff.clone();
3276    let mut refreshed_credentials = false;
3277    let method = reqwest::Method::GET;
3278    loop {
3279        let result = list_viewer_announcements_inner(
3280            configuration,
3281            &mut backoff,
3282            page_size.clone(),
3283            page_token.clone(),
3284            include_dismissed.clone(),
3285        )
3286        .await;
3287
3288        match result {
3289            Ok(result) => return Ok(result),
3290            Err(Error::ResponseError(response)) => {
3291                if !refreshed_credentials
3292                    && matches!(
3293                        response.status,
3294                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
3295                    )
3296                {
3297                    configuration.qcs_config.refresh().await?;
3298                    refreshed_credentials = true;
3299                    continue;
3300                } else if let Some(duration) = response.retry_delay {
3301                    tokio::time::sleep(duration).await;
3302                    continue;
3303                }
3304
3305                return Err(Error::ResponseError(response));
3306            }
3307            Err(Error::Reqwest(error)) => {
3308                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
3309                    tokio::time::sleep(duration).await;
3310                    continue;
3311                }
3312
3313                return Err(Error::Reqwest(error));
3314            }
3315            Err(Error::Io(error)) => {
3316                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
3317                    tokio::time::sleep(duration).await;
3318                    continue;
3319                }
3320
3321                return Err(Error::Io(error));
3322            }
3323            Err(error) => return Err(error),
3324        }
3325    }
3326}
3327async fn put_viewer_user_onboarding_completed_inner(
3328    configuration: &configuration::Configuration,
3329    backoff: &mut ExponentialBackoff,
3330    viewer_user_onboarding_completed: Option<crate::models::ViewerUserOnboardingCompleted>,
3331) -> Result<
3332    crate::models::ViewerUserOnboardingCompleted,
3333    Error<PutViewerUserOnboardingCompletedError>,
3334> {
3335    let local_var_configuration = configuration;
3336
3337    let local_var_client = &local_var_configuration.client;
3338
3339    let local_var_uri_str = format!(
3340        "{}/v1/viewer/onboardingCompleted",
3341        local_var_configuration.qcs_config.api_url()
3342    );
3343    let mut local_var_req_builder =
3344        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
3345
3346    #[cfg(feature = "tracing")]
3347    {
3348        // Ignore parsing errors if the URL is invalid for some reason.
3349        // If it is invalid, it will turn up as an error later when actually making the request.
3350        let local_var_do_tracing =
3351            local_var_uri_str
3352                .parse::<::url::Url>()
3353                .ok()
3354                .map_or(true, |url| {
3355                    configuration
3356                        .qcs_config
3357                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
3358                });
3359
3360        if local_var_do_tracing {
3361            ::tracing::debug!(
3362                url=%local_var_uri_str,
3363                method="PUT",
3364                "making put_viewer_user_onboarding_completed request",
3365            );
3366        }
3367    }
3368
3369    // Use the QCS Bearer token if a client OAuthSession is present,
3370    // but do not require one when the security schema says it is optional.
3371    {
3372        use qcs_api_client_common::configuration::TokenError;
3373
3374        #[allow(
3375            clippy::nonminimal_bool,
3376            clippy::eq_op,
3377            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
3378        )]
3379        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
3380
3381        let token = local_var_configuration
3382            .qcs_config
3383            .get_bearer_access_token()
3384            .await;
3385
3386        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
3387            // the client is configured without any OAuthSession, but this call does not require one.
3388            #[cfg(feature = "tracing")]
3389            tracing::debug!(
3390                "No client credentials found, but this call does not require authentication."
3391            );
3392        } else {
3393            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
3394        }
3395    }
3396
3397    local_var_req_builder = local_var_req_builder.json(&viewer_user_onboarding_completed);
3398
3399    let local_var_req = local_var_req_builder.build()?;
3400    let local_var_resp = local_var_client.execute(local_var_req).await?;
3401
3402    let local_var_status = local_var_resp.status();
3403
3404    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
3405        let local_var_content = local_var_resp.text().await?;
3406        serde_json::from_str(&local_var_content).map_err(Error::from)
3407    } else {
3408        let local_var_retry_delay =
3409            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
3410        let local_var_content = local_var_resp.text().await?;
3411        let local_var_entity: Option<PutViewerUserOnboardingCompletedError> =
3412            serde_json::from_str(&local_var_content).ok();
3413        let local_var_error = ResponseContent {
3414            status: local_var_status,
3415            content: local_var_content,
3416            entity: local_var_entity,
3417            retry_delay: local_var_retry_delay,
3418        };
3419        Err(Error::ResponseError(local_var_error))
3420    }
3421}
3422
3423/// Update the onboarding status of the authenticated user.
3424pub async fn put_viewer_user_onboarding_completed(
3425    configuration: &configuration::Configuration,
3426    viewer_user_onboarding_completed: Option<crate::models::ViewerUserOnboardingCompleted>,
3427) -> Result<
3428    crate::models::ViewerUserOnboardingCompleted,
3429    Error<PutViewerUserOnboardingCompletedError>,
3430> {
3431    let mut backoff = configuration.backoff.clone();
3432    let mut refreshed_credentials = false;
3433    let method = reqwest::Method::PUT;
3434    loop {
3435        let result = put_viewer_user_onboarding_completed_inner(
3436            configuration,
3437            &mut backoff,
3438            viewer_user_onboarding_completed.clone(),
3439        )
3440        .await;
3441
3442        match result {
3443            Ok(result) => return Ok(result),
3444            Err(Error::ResponseError(response)) => {
3445                if !refreshed_credentials
3446                    && matches!(
3447                        response.status,
3448                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
3449                    )
3450                {
3451                    configuration.qcs_config.refresh().await?;
3452                    refreshed_credentials = true;
3453                    continue;
3454                } else if let Some(duration) = response.retry_delay {
3455                    tokio::time::sleep(duration).await;
3456                    continue;
3457                }
3458
3459                return Err(Error::ResponseError(response));
3460            }
3461            Err(Error::Reqwest(error)) => {
3462                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
3463                    tokio::time::sleep(duration).await;
3464                    continue;
3465                }
3466
3467                return Err(Error::Reqwest(error));
3468            }
3469            Err(Error::Io(error)) => {
3470                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
3471                    tokio::time::sleep(duration).await;
3472                    continue;
3473                }
3474
3475                return Err(Error::Io(error));
3476            }
3477            Err(error) => return Err(error),
3478        }
3479    }
3480}
3481async fn remove_group_user_inner(
3482    configuration: &configuration::Configuration,
3483    backoff: &mut ExponentialBackoff,
3484    remove_group_user_request: crate::models::RemoveGroupUserRequest,
3485) -> Result<(), Error<RemoveGroupUserError>> {
3486    let local_var_configuration = configuration;
3487
3488    let local_var_client = &local_var_configuration.client;
3489
3490    let local_var_uri_str = format!(
3491        "{}/v1/groups:removeUser",
3492        local_var_configuration.qcs_config.api_url()
3493    );
3494    let mut local_var_req_builder =
3495        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
3496
3497    #[cfg(feature = "tracing")]
3498    {
3499        // Ignore parsing errors if the URL is invalid for some reason.
3500        // If it is invalid, it will turn up as an error later when actually making the request.
3501        let local_var_do_tracing =
3502            local_var_uri_str
3503                .parse::<::url::Url>()
3504                .ok()
3505                .map_or(true, |url| {
3506                    configuration
3507                        .qcs_config
3508                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
3509                });
3510
3511        if local_var_do_tracing {
3512            ::tracing::debug!(
3513                url=%local_var_uri_str,
3514                method="POST",
3515                "making remove_group_user request",
3516            );
3517        }
3518    }
3519
3520    // Use the QCS Bearer token if a client OAuthSession is present,
3521    // but do not require one when the security schema says it is optional.
3522    {
3523        use qcs_api_client_common::configuration::TokenError;
3524
3525        #[allow(
3526            clippy::nonminimal_bool,
3527            clippy::eq_op,
3528            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
3529        )]
3530        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
3531
3532        let token = local_var_configuration
3533            .qcs_config
3534            .get_bearer_access_token()
3535            .await;
3536
3537        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
3538            // the client is configured without any OAuthSession, but this call does not require one.
3539            #[cfg(feature = "tracing")]
3540            tracing::debug!(
3541                "No client credentials found, but this call does not require authentication."
3542            );
3543        } else {
3544            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
3545        }
3546    }
3547
3548    local_var_req_builder = local_var_req_builder.json(&remove_group_user_request);
3549
3550    let local_var_req = local_var_req_builder.build()?;
3551    let local_var_resp = local_var_client.execute(local_var_req).await?;
3552
3553    let local_var_status = local_var_resp.status();
3554
3555    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
3556        Ok(())
3557    } else {
3558        let local_var_retry_delay =
3559            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
3560        let local_var_content = local_var_resp.text().await?;
3561        let local_var_entity: Option<RemoveGroupUserError> =
3562            serde_json::from_str(&local_var_content).ok();
3563        let local_var_error = ResponseContent {
3564            status: local_var_status,
3565            content: local_var_content,
3566            entity: local_var_entity,
3567            retry_delay: local_var_retry_delay,
3568        };
3569        Err(Error::ResponseError(local_var_error))
3570    }
3571}
3572
3573/// Remove a user from a group. Note, group membership may take several minutes to update within our identity provider. After removing a user from a group, please allow up to 60 minutes for changes to be reflected.
3574pub async fn remove_group_user(
3575    configuration: &configuration::Configuration,
3576    remove_group_user_request: crate::models::RemoveGroupUserRequest,
3577) -> Result<(), Error<RemoveGroupUserError>> {
3578    let mut backoff = configuration.backoff.clone();
3579    let mut refreshed_credentials = false;
3580    let method = reqwest::Method::POST;
3581    loop {
3582        let result = remove_group_user_inner(
3583            configuration,
3584            &mut backoff,
3585            remove_group_user_request.clone(),
3586        )
3587        .await;
3588
3589        match result {
3590            Ok(result) => return Ok(result),
3591            Err(Error::ResponseError(response)) => {
3592                if !refreshed_credentials
3593                    && matches!(
3594                        response.status,
3595                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
3596                    )
3597                {
3598                    configuration.qcs_config.refresh().await?;
3599                    refreshed_credentials = true;
3600                    continue;
3601                } else if let Some(duration) = response.retry_delay {
3602                    tokio::time::sleep(duration).await;
3603                    continue;
3604                }
3605
3606                return Err(Error::ResponseError(response));
3607            }
3608            Err(Error::Reqwest(error)) => {
3609                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
3610                    tokio::time::sleep(duration).await;
3611                    continue;
3612                }
3613
3614                return Err(Error::Reqwest(error));
3615            }
3616            Err(Error::Io(error)) => {
3617                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
3618                    tokio::time::sleep(duration).await;
3619                    continue;
3620                }
3621
3622                return Err(Error::Io(error));
3623            }
3624            Err(error) => return Err(error),
3625        }
3626    }
3627}
3628async fn update_viewer_user_profile_inner(
3629    configuration: &configuration::Configuration,
3630    backoff: &mut ExponentialBackoff,
3631    update_viewer_user_profile_request: crate::models::UpdateViewerUserProfileRequest,
3632) -> Result<crate::models::User, Error<UpdateViewerUserProfileError>> {
3633    let local_var_configuration = configuration;
3634
3635    let local_var_client = &local_var_configuration.client;
3636
3637    let local_var_uri_str = format!(
3638        "{}/v1/viewer/userProfile",
3639        local_var_configuration.qcs_config.api_url()
3640    );
3641    let mut local_var_req_builder =
3642        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
3643
3644    #[cfg(feature = "tracing")]
3645    {
3646        // Ignore parsing errors if the URL is invalid for some reason.
3647        // If it is invalid, it will turn up as an error later when actually making the request.
3648        let local_var_do_tracing =
3649            local_var_uri_str
3650                .parse::<::url::Url>()
3651                .ok()
3652                .map_or(true, |url| {
3653                    configuration
3654                        .qcs_config
3655                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
3656                });
3657
3658        if local_var_do_tracing {
3659            ::tracing::debug!(
3660                url=%local_var_uri_str,
3661                method="PUT",
3662                "making update_viewer_user_profile request",
3663            );
3664        }
3665    }
3666
3667    // Use the QCS Bearer token if a client OAuthSession is present,
3668    // but do not require one when the security schema says it is optional.
3669    {
3670        use qcs_api_client_common::configuration::TokenError;
3671
3672        #[allow(
3673            clippy::nonminimal_bool,
3674            clippy::eq_op,
3675            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
3676        )]
3677        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
3678
3679        let token = local_var_configuration
3680            .qcs_config
3681            .get_bearer_access_token()
3682            .await;
3683
3684        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
3685            // the client is configured without any OAuthSession, but this call does not require one.
3686            #[cfg(feature = "tracing")]
3687            tracing::debug!(
3688                "No client credentials found, but this call does not require authentication."
3689            );
3690        } else {
3691            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
3692        }
3693    }
3694
3695    local_var_req_builder = local_var_req_builder.json(&update_viewer_user_profile_request);
3696
3697    let local_var_req = local_var_req_builder.build()?;
3698    let local_var_resp = local_var_client.execute(local_var_req).await?;
3699
3700    let local_var_status = local_var_resp.status();
3701
3702    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
3703        let local_var_content = local_var_resp.text().await?;
3704        serde_json::from_str(&local_var_content).map_err(Error::from)
3705    } else {
3706        let local_var_retry_delay =
3707            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
3708        let local_var_content = local_var_resp.text().await?;
3709        let local_var_entity: Option<UpdateViewerUserProfileError> =
3710            serde_json::from_str(&local_var_content).ok();
3711        let local_var_error = ResponseContent {
3712            status: local_var_status,
3713            content: local_var_content,
3714            entity: local_var_entity,
3715            retry_delay: local_var_retry_delay,
3716        };
3717        Err(Error::ResponseError(local_var_error))
3718    }
3719}
3720
3721/// Update the profile of the authenticated user.
3722pub async fn update_viewer_user_profile(
3723    configuration: &configuration::Configuration,
3724    update_viewer_user_profile_request: crate::models::UpdateViewerUserProfileRequest,
3725) -> Result<crate::models::User, Error<UpdateViewerUserProfileError>> {
3726    let mut backoff = configuration.backoff.clone();
3727    let mut refreshed_credentials = false;
3728    let method = reqwest::Method::PUT;
3729    loop {
3730        let result = update_viewer_user_profile_inner(
3731            configuration,
3732            &mut backoff,
3733            update_viewer_user_profile_request.clone(),
3734        )
3735        .await;
3736
3737        match result {
3738            Ok(result) => return Ok(result),
3739            Err(Error::ResponseError(response)) => {
3740                if !refreshed_credentials
3741                    && matches!(
3742                        response.status,
3743                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
3744                    )
3745                {
3746                    configuration.qcs_config.refresh().await?;
3747                    refreshed_credentials = true;
3748                    continue;
3749                } else if let Some(duration) = response.retry_delay {
3750                    tokio::time::sleep(duration).await;
3751                    continue;
3752                }
3753
3754                return Err(Error::ResponseError(response));
3755            }
3756            Err(Error::Reqwest(error)) => {
3757                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
3758                    tokio::time::sleep(duration).await;
3759                    continue;
3760                }
3761
3762                return Err(Error::Reqwest(error));
3763            }
3764            Err(Error::Io(error)) => {
3765                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
3766                    tokio::time::sleep(duration).await;
3767                    continue;
3768                }
3769
3770                return Err(Error::Io(error));
3771            }
3772            Err(error) => return Err(error),
3773        }
3774    }
3775}