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