Skip to main content

qcs_api_client_openapi/apis/
reservations_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, ContentType, Error};
26use crate::{apis::ResponseContent, models};
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#[cfg(feature = "clap")]
36#[allow(unused, reason = "not used in all templates, but required in some")]
37use ::{miette::IntoDiagnostic as _, qcs_api_client_common::clap_utils::JsonMaybeStdin};
38
39/// Serialize command-line arguments for [`create_reservation`]
40#[cfg(feature = "clap")]
41#[derive(Debug, clap::Args)]
42pub struct CreateReservationClapParams {
43    pub create_reservation_request: JsonMaybeStdin<crate::models::CreateReservationRequest>,
44    /// Used to specify a subject account ID for a request. Does not take precedence over a corresponding request body field when one is present.
45    #[arg(long)]
46    pub x_qcs_account_id: Option<String>,
47    /// Used to specify the subject account's type for a request in conjunction with the X-QCS-ACCOUNT-ID header. Does not take precedence over a corresponding request body field when one is present.
48    #[arg(long)]
49    pub x_qcs_account_type: Option<models::AccountType>,
50}
51
52#[cfg(feature = "clap")]
53impl CreateReservationClapParams {
54    pub async fn execute(
55        self,
56        configuration: &configuration::Configuration,
57    ) -> Result<models::Reservation, miette::Error> {
58        let request = self.create_reservation_request.into_inner().into_inner();
59
60        create_reservation(
61            configuration,
62            request,
63            self.x_qcs_account_id.as_deref(),
64            self.x_qcs_account_type,
65        )
66        .await
67        .into_diagnostic()
68    }
69}
70
71/// Serialize command-line arguments for [`delete_reservation`]
72#[cfg(feature = "clap")]
73#[derive(Debug, clap::Args)]
74pub struct DeleteReservationClapParams {
75    #[arg(long)]
76    pub reservation_id: i64,
77}
78
79#[cfg(feature = "clap")]
80impl DeleteReservationClapParams {
81    pub async fn execute(
82        self,
83        configuration: &configuration::Configuration,
84    ) -> Result<models::Reservation, miette::Error> {
85        delete_reservation(configuration, self.reservation_id)
86            .await
87            .into_diagnostic()
88    }
89}
90
91/// Serialize command-line arguments for [`find_available_reservations`]
92#[cfg(feature = "clap")]
93#[derive(Debug, clap::Args)]
94pub struct FindAvailableReservationsClapParams {
95    #[arg(long)]
96    pub quantum_processor_id: String,
97    #[arg(long)]
98    pub start_time_from: String,
99    #[arg(long)]
100    pub duration: String,
101    #[arg(long)]
102    pub page_size: Option<i64>,
103    /// An opaque token that can be appended to a request query to retrieve the next page of results. Empty if there are no more results to retrieve.
104    #[arg(long)]
105    pub page_token: Option<String>,
106}
107
108#[cfg(feature = "clap")]
109impl FindAvailableReservationsClapParams {
110    pub async fn execute(
111        self,
112        configuration: &configuration::Configuration,
113    ) -> Result<models::FindAvailableReservationsResponse, miette::Error> {
114        find_available_reservations(
115            configuration,
116            self.quantum_processor_id.as_str(),
117            self.start_time_from,
118            self.duration.as_str(),
119            self.page_size,
120            self.page_token.as_deref(),
121        )
122        .await
123        .into_diagnostic()
124    }
125}
126
127/// Serialize command-line arguments for [`get_quantum_processor_calendar`]
128#[cfg(feature = "clap")]
129#[derive(Debug, clap::Args)]
130pub struct GetQuantumProcessorCalendarClapParams {
131    #[arg(long)]
132    pub quantum_processor_id: String,
133}
134
135#[cfg(feature = "clap")]
136impl GetQuantumProcessorCalendarClapParams {
137    pub async fn execute(
138        self,
139        configuration: &configuration::Configuration,
140    ) -> Result<models::QuantumProcessorCalendar, miette::Error> {
141        get_quantum_processor_calendar(configuration, self.quantum_processor_id.as_str())
142            .await
143            .into_diagnostic()
144    }
145}
146
147/// Serialize command-line arguments for [`get_reservation`]
148#[cfg(feature = "clap")]
149#[derive(Debug, clap::Args)]
150pub struct GetReservationClapParams {
151    #[arg(long)]
152    pub reservation_id: i64,
153}
154
155#[cfg(feature = "clap")]
156impl GetReservationClapParams {
157    pub async fn execute(
158        self,
159        configuration: &configuration::Configuration,
160    ) -> Result<models::Reservation, miette::Error> {
161        get_reservation(configuration, self.reservation_id)
162            .await
163            .into_diagnostic()
164    }
165}
166
167/// Serialize command-line arguments for [`list_group_reservations`]
168#[cfg(feature = "clap")]
169#[derive(Debug, clap::Args)]
170pub struct ListGroupReservationsClapParams {
171    /// URL encoded name of group for which to retrieve reservations.
172    #[arg(long)]
173    pub group_name: String,
174    #[arg(long)]
175    pub filter: Option<String>,
176    #[arg(long)]
177    pub order: Option<String>,
178    #[arg(long)]
179    pub page_size: Option<i64>,
180    /// An opaque token that can be appended to a request query to retrieve the next page of results. Empty if there are no more results to retrieve.
181    #[arg(long)]
182    pub page_token: Option<String>,
183    /// If you wish to include deleted (or cancelled) resources in your response, include `showDeleted=true`.
184    #[arg(long)]
185    pub show_deleted: Option<String>,
186}
187
188#[cfg(feature = "clap")]
189impl ListGroupReservationsClapParams {
190    pub async fn execute(
191        self,
192        configuration: &configuration::Configuration,
193    ) -> Result<models::ListReservationsResponse, miette::Error> {
194        list_group_reservations(
195            configuration,
196            self.group_name.as_str(),
197            self.filter.as_deref(),
198            self.order.as_deref(),
199            self.page_size,
200            self.page_token.as_deref(),
201            self.show_deleted.as_deref(),
202        )
203        .await
204        .into_diagnostic()
205    }
206}
207
208/// Serialize command-line arguments for [`list_reservations`]
209#[cfg(feature = "clap")]
210#[derive(Debug, clap::Args)]
211pub struct ListReservationsClapParams {
212    #[arg(long)]
213    pub filter: Option<String>,
214    #[arg(long)]
215    pub order: Option<String>,
216    #[arg(long)]
217    pub page_size: Option<i64>,
218    /// An opaque token that can be appended to a request query to retrieve the next page of results. Empty if there are no more results to retrieve.
219    #[arg(long)]
220    pub page_token: Option<String>,
221    /// If you wish to include deleted (or cancelled) resources in your response, include `showDeleted=true`.
222    #[arg(long)]
223    pub show_deleted: Option<String>,
224    /// Used to specify a subject account ID for a request. Does not take precedence over a corresponding request body field when one is present.
225    #[arg(long)]
226    pub x_qcs_account_id: Option<String>,
227    /// Used to specify the subject account's type for a request in conjunction with the X-QCS-ACCOUNT-ID header. Does not take precedence over a corresponding request body field when one is present.
228    #[arg(long)]
229    pub x_qcs_account_type: Option<models::AccountType>,
230}
231
232#[cfg(feature = "clap")]
233impl ListReservationsClapParams {
234    pub async fn execute(
235        self,
236        configuration: &configuration::Configuration,
237    ) -> Result<models::ListReservationsResponse, miette::Error> {
238        list_reservations(
239            configuration,
240            self.filter.as_deref(),
241            self.order.as_deref(),
242            self.page_size,
243            self.page_token.as_deref(),
244            self.show_deleted.as_deref(),
245            self.x_qcs_account_id.as_deref(),
246            self.x_qcs_account_type,
247        )
248        .await
249        .into_diagnostic()
250    }
251}
252
253/// struct for typed errors of method [`create_reservation`]
254#[derive(Debug, Clone, Serialize, Deserialize)]
255#[serde(untagged)]
256pub enum CreateReservationError {
257    Status401(models::Error),
258    Status402(models::Error),
259    Status403(models::Error),
260    Status409(models::Error),
261    Status422(models::Error),
262    UnknownValue(serde_json::Value),
263}
264
265/// struct for typed errors of method [`delete_reservation`]
266#[derive(Debug, Clone, Serialize, Deserialize)]
267#[serde(untagged)]
268pub enum DeleteReservationError {
269    Status401(models::Error),
270    Status403(models::Error),
271    Status404(models::Error),
272    UnknownValue(serde_json::Value),
273}
274
275/// struct for typed errors of method [`find_available_reservations`]
276#[derive(Debug, Clone, Serialize, Deserialize)]
277#[serde(untagged)]
278pub enum FindAvailableReservationsError {
279    Status401(models::Error),
280    Status422(models::Error),
281    UnknownValue(serde_json::Value),
282}
283
284/// struct for typed errors of method [`get_quantum_processor_calendar`]
285#[derive(Debug, Clone, Serialize, Deserialize)]
286#[serde(untagged)]
287pub enum GetQuantumProcessorCalendarError {
288    Status403(models::Error),
289    Status404(models::Error),
290    UnknownValue(serde_json::Value),
291}
292
293/// struct for typed errors of method [`get_reservation`]
294#[derive(Debug, Clone, Serialize, Deserialize)]
295#[serde(untagged)]
296pub enum GetReservationError {
297    Status401(models::Error),
298    Status403(models::Error),
299    Status404(models::Error),
300    UnknownValue(serde_json::Value),
301}
302
303/// struct for typed errors of method [`list_group_reservations`]
304#[derive(Debug, Clone, Serialize, Deserialize)]
305#[serde(untagged)]
306pub enum ListGroupReservationsError {
307    Status401(models::Error),
308    Status422(models::Error),
309    UnknownValue(serde_json::Value),
310}
311
312/// struct for typed errors of method [`list_reservations`]
313#[derive(Debug, Clone, Serialize, Deserialize)]
314#[serde(untagged)]
315pub enum ListReservationsError {
316    Status401(models::Error),
317    Status422(models::Error),
318    UnknownValue(serde_json::Value),
319}
320
321async fn create_reservation_inner(
322    configuration: &configuration::Configuration,
323    backoff: &mut ExponentialBackoff,
324    create_reservation_request: crate::models::CreateReservationRequest,
325    x_qcs_account_id: Option<&str>,
326    x_qcs_account_type: Option<models::AccountType>,
327) -> Result<models::Reservation, Error<CreateReservationError>> {
328    let local_var_configuration = configuration;
329    // add a prefix to parameters to efficiently prevent name collisions
330    let p_body_create_reservation_request = create_reservation_request;
331    let p_header_x_qcs_account_id = x_qcs_account_id;
332    let p_header_x_qcs_account_type = x_qcs_account_type;
333
334    let local_var_client = &local_var_configuration.client;
335
336    let local_var_uri_str = format!(
337        "{}/v1/reservations",
338        local_var_configuration.qcs_config.api_url()
339    );
340    let mut local_var_req_builder =
341        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
342
343    #[cfg(feature = "tracing")]
344    {
345        // Ignore parsing errors if the URL is invalid for some reason.
346        // If it is invalid, it will turn up as an error later when actually making the request.
347        let local_var_do_tracing = local_var_uri_str
348            .parse::<::url::Url>()
349            .ok()
350            .is_none_or(|url| {
351                configuration
352                    .qcs_config
353                    .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
354            });
355
356        if local_var_do_tracing {
357            ::tracing::debug!(
358                url=%local_var_uri_str,
359                method="POST",
360                "making create_reservation request",
361            );
362        }
363    }
364
365    if let Some(local_var_param_value) = p_header_x_qcs_account_id {
366        local_var_req_builder =
367            local_var_req_builder.header("x-qcs-account-id", local_var_param_value.to_string());
368    }
369    if let Some(local_var_param_value) = p_header_x_qcs_account_type {
370        local_var_req_builder =
371            local_var_req_builder.header("x-qcs-account-type", local_var_param_value.to_string());
372    }
373
374    // Use the QCS Bearer token if a client OAuthSession is present,
375    // but do not require one when the security schema says it is optional.
376    {
377        use qcs_api_client_common::configuration::TokenError;
378
379        #[allow(
380            clippy::nonminimal_bool,
381            clippy::eq_op,
382            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
383        )]
384        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
385
386        let token = local_var_configuration
387            .qcs_config
388            .get_bearer_access_token()
389            .await;
390
391        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
392            // the client is configured without any OAuthSession, but this call does not require one.
393            #[cfg(feature = "tracing")]
394            tracing::debug!(
395                "No client credentials found, but this call does not require authentication."
396            );
397        } else {
398            local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
399        }
400    }
401
402    local_var_req_builder = local_var_req_builder.json(&p_body_create_reservation_request);
403
404    let local_var_req = local_var_req_builder.build()?;
405    let local_var_resp = local_var_client.execute(local_var_req).await?;
406
407    let local_var_status = local_var_resp.status();
408    let local_var_raw_content_type = local_var_resp
409        .headers()
410        .get("content-type")
411        .and_then(|v| v.to_str().ok())
412        .unwrap_or("application/octet-stream")
413        .to_string();
414    let local_var_content_type = super::ContentType::from(local_var_raw_content_type.as_str());
415
416    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
417        let local_var_content = local_var_resp.text().await?;
418        match local_var_content_type {
419            ContentType::Json => serde_path_to_error::deserialize(
420                &mut serde_json::Deserializer::from_str(&local_var_content),
421            )
422            .map_err(Error::from),
423            ContentType::Text => Err(Error::InvalidContentType {
424                content_type: local_var_raw_content_type,
425                return_type: "models::Reservation",
426            }),
427            ContentType::Unsupported(unknown_type) => Err(Error::InvalidContentType {
428                content_type: unknown_type,
429                return_type: "models::Reservation",
430            }),
431        }
432    } else {
433        let local_var_retry_delay =
434            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
435        let local_var_content = local_var_resp.text().await?;
436        let local_var_entity: Option<CreateReservationError> =
437            serde_json::from_str(&local_var_content).ok();
438        let local_var_error = ResponseContent {
439            status: local_var_status,
440            content: local_var_content,
441            entity: local_var_entity,
442            retry_delay: local_var_retry_delay,
443        };
444        Err(Error::ResponseError(local_var_error))
445    }
446}
447
448/// Create a new reservation.  The following precedence applies when specifying the reservation subject account ID and type: * request body `accountId` field, or if unset then `X-QCS-ACCOUNT-ID` header, or if unset then requesting user's ID. * request body `accountType` field, or if unset then `X-QCS-ACCOUNT-TYPE` header, or if unset then \"user\" type.
449pub async fn create_reservation(
450    configuration: &configuration::Configuration,
451    create_reservation_request: crate::models::CreateReservationRequest,
452    x_qcs_account_id: Option<&str>,
453    x_qcs_account_type: Option<models::AccountType>,
454) -> Result<models::Reservation, Error<CreateReservationError>> {
455    let mut backoff = configuration.backoff.clone();
456    let mut refreshed_credentials = false;
457    let method = reqwest::Method::POST;
458    loop {
459        let result = create_reservation_inner(
460            configuration,
461            &mut backoff,
462            create_reservation_request.clone(),
463            x_qcs_account_id.clone(),
464            x_qcs_account_type.clone(),
465        )
466        .await;
467
468        match result {
469            Ok(result) => return Ok(result),
470            Err(Error::ResponseError(response)) => {
471                if !refreshed_credentials
472                    && matches!(
473                        response.status,
474                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
475                    )
476                {
477                    configuration.qcs_config.refresh().await?;
478                    refreshed_credentials = true;
479                    continue;
480                } else if let Some(duration) = response.retry_delay {
481                    tokio::time::sleep(duration).await;
482                    continue;
483                }
484
485                return Err(Error::ResponseError(response));
486            }
487            Err(Error::Reqwest(error)) => {
488                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
489                    tokio::time::sleep(duration).await;
490                    continue;
491                }
492
493                return Err(Error::Reqwest(error));
494            }
495            Err(Error::Io(error)) => {
496                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
497                    tokio::time::sleep(duration).await;
498                    continue;
499                }
500
501                return Err(Error::Io(error));
502            }
503            Err(error) => return Err(error),
504        }
505    }
506}
507async fn delete_reservation_inner(
508    configuration: &configuration::Configuration,
509    backoff: &mut ExponentialBackoff,
510    reservation_id: i64,
511) -> Result<models::Reservation, Error<DeleteReservationError>> {
512    let local_var_configuration = configuration;
513    // add a prefix to parameters to efficiently prevent name collisions
514    let p_path_reservation_id = reservation_id;
515
516    let local_var_client = &local_var_configuration.client;
517
518    let local_var_uri_str = format!(
519        "{}/v1/reservations/{reservationId}",
520        local_var_configuration.qcs_config.api_url(),
521        reservationId = p_path_reservation_id
522    );
523    let mut local_var_req_builder =
524        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
525
526    #[cfg(feature = "tracing")]
527    {
528        // Ignore parsing errors if the URL is invalid for some reason.
529        // If it is invalid, it will turn up as an error later when actually making the request.
530        let local_var_do_tracing = local_var_uri_str
531            .parse::<::url::Url>()
532            .ok()
533            .is_none_or(|url| {
534                configuration
535                    .qcs_config
536                    .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
537            });
538
539        if local_var_do_tracing {
540            ::tracing::debug!(
541                url=%local_var_uri_str,
542                method="DELETE",
543                "making delete_reservation request",
544            );
545        }
546    }
547
548    // Use the QCS Bearer token if a client OAuthSession is present,
549    // but do not require one when the security schema says it is optional.
550    {
551        use qcs_api_client_common::configuration::TokenError;
552
553        #[allow(
554            clippy::nonminimal_bool,
555            clippy::eq_op,
556            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
557        )]
558        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
559
560        let token = local_var_configuration
561            .qcs_config
562            .get_bearer_access_token()
563            .await;
564
565        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
566            // the client is configured without any OAuthSession, but this call does not require one.
567            #[cfg(feature = "tracing")]
568            tracing::debug!(
569                "No client credentials found, but this call does not require authentication."
570            );
571        } else {
572            local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
573        }
574    }
575
576    let local_var_req = local_var_req_builder.build()?;
577    let local_var_resp = local_var_client.execute(local_var_req).await?;
578
579    let local_var_status = local_var_resp.status();
580    let local_var_raw_content_type = local_var_resp
581        .headers()
582        .get("content-type")
583        .and_then(|v| v.to_str().ok())
584        .unwrap_or("application/octet-stream")
585        .to_string();
586    let local_var_content_type = super::ContentType::from(local_var_raw_content_type.as_str());
587
588    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
589        let local_var_content = local_var_resp.text().await?;
590        match local_var_content_type {
591            ContentType::Json => serde_path_to_error::deserialize(
592                &mut serde_json::Deserializer::from_str(&local_var_content),
593            )
594            .map_err(Error::from),
595            ContentType::Text => Err(Error::InvalidContentType {
596                content_type: local_var_raw_content_type,
597                return_type: "models::Reservation",
598            }),
599            ContentType::Unsupported(unknown_type) => Err(Error::InvalidContentType {
600                content_type: unknown_type,
601                return_type: "models::Reservation",
602            }),
603        }
604    } else {
605        let local_var_retry_delay =
606            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
607        let local_var_content = local_var_resp.text().await?;
608        let local_var_entity: Option<DeleteReservationError> =
609            serde_json::from_str(&local_var_content).ok();
610        let local_var_error = ResponseContent {
611            status: local_var_status,
612            content: local_var_content,
613            entity: local_var_entity,
614            retry_delay: local_var_retry_delay,
615        };
616        Err(Error::ResponseError(local_var_error))
617    }
618}
619
620/// Cancel an existing reservation for the user.
621pub async fn delete_reservation(
622    configuration: &configuration::Configuration,
623    reservation_id: i64,
624) -> Result<models::Reservation, Error<DeleteReservationError>> {
625    let mut backoff = configuration.backoff.clone();
626    let mut refreshed_credentials = false;
627    let method = reqwest::Method::DELETE;
628    loop {
629        let result =
630            delete_reservation_inner(configuration, &mut backoff, reservation_id.clone()).await;
631
632        match result {
633            Ok(result) => return Ok(result),
634            Err(Error::ResponseError(response)) => {
635                if !refreshed_credentials
636                    && matches!(
637                        response.status,
638                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
639                    )
640                {
641                    configuration.qcs_config.refresh().await?;
642                    refreshed_credentials = true;
643                    continue;
644                } else if let Some(duration) = response.retry_delay {
645                    tokio::time::sleep(duration).await;
646                    continue;
647                }
648
649                return Err(Error::ResponseError(response));
650            }
651            Err(Error::Reqwest(error)) => {
652                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
653                    tokio::time::sleep(duration).await;
654                    continue;
655                }
656
657                return Err(Error::Reqwest(error));
658            }
659            Err(Error::Io(error)) => {
660                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
661                    tokio::time::sleep(duration).await;
662                    continue;
663                }
664
665                return Err(Error::Io(error));
666            }
667            Err(error) => return Err(error),
668        }
669    }
670}
671async fn find_available_reservations_inner(
672    configuration: &configuration::Configuration,
673    backoff: &mut ExponentialBackoff,
674    quantum_processor_id: &str,
675    start_time_from: String,
676    duration: &str,
677    page_size: Option<i64>,
678    page_token: Option<&str>,
679) -> Result<models::FindAvailableReservationsResponse, Error<FindAvailableReservationsError>> {
680    let local_var_configuration = configuration;
681    // add a prefix to parameters to efficiently prevent name collisions
682    let p_query_quantum_processor_id = quantum_processor_id;
683    let p_query_start_time_from = start_time_from;
684    let p_query_duration = duration;
685    let p_query_page_size = page_size;
686    let p_query_page_token = page_token;
687
688    let local_var_client = &local_var_configuration.client;
689
690    let local_var_uri_str = format!(
691        "{}/v1/reservations:findAvailable",
692        local_var_configuration.qcs_config.api_url()
693    );
694    let mut local_var_req_builder =
695        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
696
697    #[cfg(feature = "tracing")]
698    {
699        // Ignore parsing errors if the URL is invalid for some reason.
700        // If it is invalid, it will turn up as an error later when actually making the request.
701        let local_var_do_tracing = local_var_uri_str
702            .parse::<::url::Url>()
703            .ok()
704            .is_none_or(|url| {
705                configuration
706                    .qcs_config
707                    .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
708            });
709
710        if local_var_do_tracing {
711            ::tracing::debug!(
712                url=%local_var_uri_str,
713                method="GET",
714                "making find_available_reservations request",
715            );
716        }
717    }
718
719    if let Some(ref local_var_str) = p_query_page_size {
720        local_var_req_builder =
721            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
722    }
723    if let Some(ref local_var_str) = p_query_page_token {
724        local_var_req_builder =
725            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
726    }
727    local_var_req_builder = local_var_req_builder.query(&[(
728        "quantumProcessorId",
729        &p_query_quantum_processor_id.to_string(),
730    )]);
731    local_var_req_builder =
732        local_var_req_builder.query(&[("startTimeFrom", &p_query_start_time_from.to_string())]);
733    local_var_req_builder =
734        local_var_req_builder.query(&[("duration", &p_query_duration.to_string())]);
735
736    // Use the QCS Bearer token if a client OAuthSession is present,
737    // but do not require one when the security schema says it is optional.
738    {
739        use qcs_api_client_common::configuration::TokenError;
740
741        #[allow(
742            clippy::nonminimal_bool,
743            clippy::eq_op,
744            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
745        )]
746        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
747
748        let token = local_var_configuration
749            .qcs_config
750            .get_bearer_access_token()
751            .await;
752
753        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
754            // the client is configured without any OAuthSession, but this call does not require one.
755            #[cfg(feature = "tracing")]
756            tracing::debug!(
757                "No client credentials found, but this call does not require authentication."
758            );
759        } else {
760            local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
761        }
762    }
763
764    let local_var_req = local_var_req_builder.build()?;
765    let local_var_resp = local_var_client.execute(local_var_req).await?;
766
767    let local_var_status = local_var_resp.status();
768    let local_var_raw_content_type = local_var_resp
769        .headers()
770        .get("content-type")
771        .and_then(|v| v.to_str().ok())
772        .unwrap_or("application/octet-stream")
773        .to_string();
774    let local_var_content_type = super::ContentType::from(local_var_raw_content_type.as_str());
775
776    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
777        let local_var_content = local_var_resp.text().await?;
778        match local_var_content_type {
779            ContentType::Json => serde_path_to_error::deserialize(
780                &mut serde_json::Deserializer::from_str(&local_var_content),
781            )
782            .map_err(Error::from),
783            ContentType::Text => Err(Error::InvalidContentType {
784                content_type: local_var_raw_content_type,
785                return_type: "models::FindAvailableReservationsResponse",
786            }),
787            ContentType::Unsupported(unknown_type) => Err(Error::InvalidContentType {
788                content_type: unknown_type,
789                return_type: "models::FindAvailableReservationsResponse",
790            }),
791        }
792    } else {
793        let local_var_retry_delay =
794            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
795        let local_var_content = local_var_resp.text().await?;
796        let local_var_entity: Option<FindAvailableReservationsError> =
797            serde_json::from_str(&local_var_content).ok();
798        let local_var_error = ResponseContent {
799            status: local_var_status,
800            content: local_var_content,
801            entity: local_var_entity,
802            retry_delay: local_var_retry_delay,
803        };
804        Err(Error::ResponseError(local_var_error))
805    }
806}
807
808/// List currently available reservations on the requested Rigetti quantum computer.
809pub async fn find_available_reservations(
810    configuration: &configuration::Configuration,
811    quantum_processor_id: &str,
812    start_time_from: String,
813    duration: &str,
814    page_size: Option<i64>,
815    page_token: Option<&str>,
816) -> Result<models::FindAvailableReservationsResponse, Error<FindAvailableReservationsError>> {
817    let mut backoff = configuration.backoff.clone();
818    let mut refreshed_credentials = false;
819    let method = reqwest::Method::GET;
820    loop {
821        let result = find_available_reservations_inner(
822            configuration,
823            &mut backoff,
824            quantum_processor_id.clone(),
825            start_time_from.clone(),
826            duration.clone(),
827            page_size.clone(),
828            page_token.clone(),
829        )
830        .await;
831
832        match result {
833            Ok(result) => return Ok(result),
834            Err(Error::ResponseError(response)) => {
835                if !refreshed_credentials
836                    && matches!(
837                        response.status,
838                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
839                    )
840                {
841                    configuration.qcs_config.refresh().await?;
842                    refreshed_credentials = true;
843                    continue;
844                } else if let Some(duration) = response.retry_delay {
845                    tokio::time::sleep(duration).await;
846                    continue;
847                }
848
849                return Err(Error::ResponseError(response));
850            }
851            Err(Error::Reqwest(error)) => {
852                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
853                    tokio::time::sleep(duration).await;
854                    continue;
855                }
856
857                return Err(Error::Reqwest(error));
858            }
859            Err(Error::Io(error)) => {
860                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
861                    tokio::time::sleep(duration).await;
862                    continue;
863                }
864
865                return Err(Error::Io(error));
866            }
867            Err(error) => return Err(error),
868        }
869    }
870}
871async fn get_quantum_processor_calendar_inner(
872    configuration: &configuration::Configuration,
873    backoff: &mut ExponentialBackoff,
874    quantum_processor_id: &str,
875) -> Result<models::QuantumProcessorCalendar, Error<GetQuantumProcessorCalendarError>> {
876    let local_var_configuration = configuration;
877    // add a prefix to parameters to efficiently prevent name collisions
878    let p_path_quantum_processor_id = quantum_processor_id;
879
880    let local_var_client = &local_var_configuration.client;
881
882    let local_var_uri_str = format!(
883        "{}/v1/calendars/{quantumProcessorId}",
884        local_var_configuration.qcs_config.api_url(),
885        quantumProcessorId = crate::apis::urlencode(p_path_quantum_processor_id)
886    );
887    let mut local_var_req_builder =
888        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
889
890    #[cfg(feature = "tracing")]
891    {
892        // Ignore parsing errors if the URL is invalid for some reason.
893        // If it is invalid, it will turn up as an error later when actually making the request.
894        let local_var_do_tracing = local_var_uri_str
895            .parse::<::url::Url>()
896            .ok()
897            .is_none_or(|url| {
898                configuration
899                    .qcs_config
900                    .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
901            });
902
903        if local_var_do_tracing {
904            ::tracing::debug!(
905                url=%local_var_uri_str,
906                method="GET",
907                "making get_quantum_processor_calendar request",
908            );
909        }
910    }
911
912    // Use the QCS Bearer token if a client OAuthSession is present,
913    // but do not require one when the security schema says it is optional.
914    {
915        use qcs_api_client_common::configuration::TokenError;
916
917        #[allow(
918            clippy::nonminimal_bool,
919            clippy::eq_op,
920            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
921        )]
922        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
923
924        let token = local_var_configuration
925            .qcs_config
926            .get_bearer_access_token()
927            .await;
928
929        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
930            // the client is configured without any OAuthSession, but this call does not require one.
931            #[cfg(feature = "tracing")]
932            tracing::debug!(
933                "No client credentials found, but this call does not require authentication."
934            );
935        } else {
936            local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
937        }
938    }
939
940    let local_var_req = local_var_req_builder.build()?;
941    let local_var_resp = local_var_client.execute(local_var_req).await?;
942
943    let local_var_status = local_var_resp.status();
944    let local_var_raw_content_type = local_var_resp
945        .headers()
946        .get("content-type")
947        .and_then(|v| v.to_str().ok())
948        .unwrap_or("application/octet-stream")
949        .to_string();
950    let local_var_content_type = super::ContentType::from(local_var_raw_content_type.as_str());
951
952    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
953        let local_var_content = local_var_resp.text().await?;
954        match local_var_content_type {
955            ContentType::Json => serde_path_to_error::deserialize(
956                &mut serde_json::Deserializer::from_str(&local_var_content),
957            )
958            .map_err(Error::from),
959            ContentType::Text => Err(Error::InvalidContentType {
960                content_type: local_var_raw_content_type,
961                return_type: "models::QuantumProcessorCalendar",
962            }),
963            ContentType::Unsupported(unknown_type) => Err(Error::InvalidContentType {
964                content_type: unknown_type,
965                return_type: "models::QuantumProcessorCalendar",
966            }),
967        }
968    } else {
969        let local_var_retry_delay =
970            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
971        let local_var_content = local_var_resp.text().await?;
972        let local_var_entity: Option<GetQuantumProcessorCalendarError> =
973            serde_json::from_str(&local_var_content).ok();
974        let local_var_error = ResponseContent {
975            status: local_var_status,
976            content: local_var_content,
977            entity: local_var_entity,
978            retry_delay: local_var_retry_delay,
979        };
980        Err(Error::ResponseError(local_var_error))
981    }
982}
983
984/// Get calendar details for the requested quantum processor.
985pub async fn get_quantum_processor_calendar(
986    configuration: &configuration::Configuration,
987    quantum_processor_id: &str,
988) -> Result<models::QuantumProcessorCalendar, Error<GetQuantumProcessorCalendarError>> {
989    let mut backoff = configuration.backoff.clone();
990    let mut refreshed_credentials = false;
991    let method = reqwest::Method::GET;
992    loop {
993        let result = get_quantum_processor_calendar_inner(
994            configuration,
995            &mut backoff,
996            quantum_processor_id.clone(),
997        )
998        .await;
999
1000        match result {
1001            Ok(result) => return Ok(result),
1002            Err(Error::ResponseError(response)) => {
1003                if !refreshed_credentials
1004                    && matches!(
1005                        response.status,
1006                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1007                    )
1008                {
1009                    configuration.qcs_config.refresh().await?;
1010                    refreshed_credentials = true;
1011                    continue;
1012                } else if let Some(duration) = response.retry_delay {
1013                    tokio::time::sleep(duration).await;
1014                    continue;
1015                }
1016
1017                return Err(Error::ResponseError(response));
1018            }
1019            Err(Error::Reqwest(error)) => {
1020                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1021                    tokio::time::sleep(duration).await;
1022                    continue;
1023                }
1024
1025                return Err(Error::Reqwest(error));
1026            }
1027            Err(Error::Io(error)) => {
1028                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1029                    tokio::time::sleep(duration).await;
1030                    continue;
1031                }
1032
1033                return Err(Error::Io(error));
1034            }
1035            Err(error) => return Err(error),
1036        }
1037    }
1038}
1039async fn get_reservation_inner(
1040    configuration: &configuration::Configuration,
1041    backoff: &mut ExponentialBackoff,
1042    reservation_id: i64,
1043) -> Result<models::Reservation, Error<GetReservationError>> {
1044    let local_var_configuration = configuration;
1045    // add a prefix to parameters to efficiently prevent name collisions
1046    let p_path_reservation_id = reservation_id;
1047
1048    let local_var_client = &local_var_configuration.client;
1049
1050    let local_var_uri_str = format!(
1051        "{}/v1/reservations/{reservationId}",
1052        local_var_configuration.qcs_config.api_url(),
1053        reservationId = p_path_reservation_id
1054    );
1055    let mut local_var_req_builder =
1056        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1057
1058    #[cfg(feature = "tracing")]
1059    {
1060        // Ignore parsing errors if the URL is invalid for some reason.
1061        // If it is invalid, it will turn up as an error later when actually making the request.
1062        let local_var_do_tracing = local_var_uri_str
1063            .parse::<::url::Url>()
1064            .ok()
1065            .is_none_or(|url| {
1066                configuration
1067                    .qcs_config
1068                    .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1069            });
1070
1071        if local_var_do_tracing {
1072            ::tracing::debug!(
1073                url=%local_var_uri_str,
1074                method="GET",
1075                "making get_reservation request",
1076            );
1077        }
1078    }
1079
1080    // Use the QCS Bearer token if a client OAuthSession is present,
1081    // but do not require one when the security schema says it is optional.
1082    {
1083        use qcs_api_client_common::configuration::TokenError;
1084
1085        #[allow(
1086            clippy::nonminimal_bool,
1087            clippy::eq_op,
1088            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1089        )]
1090        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1091
1092        let token = local_var_configuration
1093            .qcs_config
1094            .get_bearer_access_token()
1095            .await;
1096
1097        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1098            // the client is configured without any OAuthSession, but this call does not require one.
1099            #[cfg(feature = "tracing")]
1100            tracing::debug!(
1101                "No client credentials found, but this call does not require authentication."
1102            );
1103        } else {
1104            local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
1105        }
1106    }
1107
1108    let local_var_req = local_var_req_builder.build()?;
1109    let local_var_resp = local_var_client.execute(local_var_req).await?;
1110
1111    let local_var_status = local_var_resp.status();
1112    let local_var_raw_content_type = local_var_resp
1113        .headers()
1114        .get("content-type")
1115        .and_then(|v| v.to_str().ok())
1116        .unwrap_or("application/octet-stream")
1117        .to_string();
1118    let local_var_content_type = super::ContentType::from(local_var_raw_content_type.as_str());
1119
1120    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1121        let local_var_content = local_var_resp.text().await?;
1122        match local_var_content_type {
1123            ContentType::Json => serde_path_to_error::deserialize(
1124                &mut serde_json::Deserializer::from_str(&local_var_content),
1125            )
1126            .map_err(Error::from),
1127            ContentType::Text => Err(Error::InvalidContentType {
1128                content_type: local_var_raw_content_type,
1129                return_type: "models::Reservation",
1130            }),
1131            ContentType::Unsupported(unknown_type) => Err(Error::InvalidContentType {
1132                content_type: unknown_type,
1133                return_type: "models::Reservation",
1134            }),
1135        }
1136    } else {
1137        let local_var_retry_delay =
1138            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1139        let local_var_content = local_var_resp.text().await?;
1140        let local_var_entity: Option<GetReservationError> =
1141            serde_json::from_str(&local_var_content).ok();
1142        let local_var_error = ResponseContent {
1143            status: local_var_status,
1144            content: local_var_content,
1145            entity: local_var_entity,
1146            retry_delay: local_var_retry_delay,
1147        };
1148        Err(Error::ResponseError(local_var_error))
1149    }
1150}
1151
1152/// Find an existing reservation by ID.
1153pub async fn get_reservation(
1154    configuration: &configuration::Configuration,
1155    reservation_id: i64,
1156) -> Result<models::Reservation, Error<GetReservationError>> {
1157    let mut backoff = configuration.backoff.clone();
1158    let mut refreshed_credentials = false;
1159    let method = reqwest::Method::GET;
1160    loop {
1161        let result =
1162            get_reservation_inner(configuration, &mut backoff, reservation_id.clone()).await;
1163
1164        match result {
1165            Ok(result) => return Ok(result),
1166            Err(Error::ResponseError(response)) => {
1167                if !refreshed_credentials
1168                    && matches!(
1169                        response.status,
1170                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1171                    )
1172                {
1173                    configuration.qcs_config.refresh().await?;
1174                    refreshed_credentials = true;
1175                    continue;
1176                } else if let Some(duration) = response.retry_delay {
1177                    tokio::time::sleep(duration).await;
1178                    continue;
1179                }
1180
1181                return Err(Error::ResponseError(response));
1182            }
1183            Err(Error::Reqwest(error)) => {
1184                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1185                    tokio::time::sleep(duration).await;
1186                    continue;
1187                }
1188
1189                return Err(Error::Reqwest(error));
1190            }
1191            Err(Error::Io(error)) => {
1192                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1193                    tokio::time::sleep(duration).await;
1194                    continue;
1195                }
1196
1197                return Err(Error::Io(error));
1198            }
1199            Err(error) => return Err(error),
1200        }
1201    }
1202}
1203async fn list_group_reservations_inner(
1204    configuration: &configuration::Configuration,
1205    backoff: &mut ExponentialBackoff,
1206    group_name: &str,
1207    filter: Option<&str>,
1208    order: Option<&str>,
1209    page_size: Option<i64>,
1210    page_token: Option<&str>,
1211    show_deleted: Option<&str>,
1212) -> Result<models::ListReservationsResponse, Error<ListGroupReservationsError>> {
1213    let local_var_configuration = configuration;
1214    // add a prefix to parameters to efficiently prevent name collisions
1215    let p_path_group_name = group_name;
1216    let p_query_filter = filter;
1217    let p_query_order = order;
1218    let p_query_page_size = page_size;
1219    let p_query_page_token = page_token;
1220    let p_query_show_deleted = show_deleted;
1221
1222    let local_var_client = &local_var_configuration.client;
1223
1224    let local_var_uri_str = format!(
1225        "{}/v1/groups/{groupName}/reservations",
1226        local_var_configuration.qcs_config.api_url(),
1227        groupName = crate::apis::urlencode(p_path_group_name)
1228    );
1229    let mut local_var_req_builder =
1230        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1231
1232    #[cfg(feature = "tracing")]
1233    {
1234        // Ignore parsing errors if the URL is invalid for some reason.
1235        // If it is invalid, it will turn up as an error later when actually making the request.
1236        let local_var_do_tracing = local_var_uri_str
1237            .parse::<::url::Url>()
1238            .ok()
1239            .is_none_or(|url| {
1240                configuration
1241                    .qcs_config
1242                    .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1243            });
1244
1245        if local_var_do_tracing {
1246            ::tracing::debug!(
1247                url=%local_var_uri_str,
1248                method="GET",
1249                "making list_group_reservations request",
1250            );
1251        }
1252    }
1253
1254    if let Some(ref local_var_str) = p_query_filter {
1255        local_var_req_builder =
1256            local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
1257    }
1258    if let Some(ref local_var_str) = p_query_order {
1259        local_var_req_builder =
1260            local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
1261    }
1262    if let Some(ref local_var_str) = p_query_page_size {
1263        local_var_req_builder =
1264            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
1265    }
1266    if let Some(ref local_var_str) = p_query_page_token {
1267        local_var_req_builder =
1268            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
1269    }
1270    if let Some(ref local_var_str) = p_query_show_deleted {
1271        local_var_req_builder =
1272            local_var_req_builder.query(&[("showDeleted", &local_var_str.to_string())]);
1273    }
1274
1275    // Use the QCS Bearer token if a client OAuthSession is present,
1276    // but do not require one when the security schema says it is optional.
1277    {
1278        use qcs_api_client_common::configuration::TokenError;
1279
1280        #[allow(
1281            clippy::nonminimal_bool,
1282            clippy::eq_op,
1283            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1284        )]
1285        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1286
1287        let token = local_var_configuration
1288            .qcs_config
1289            .get_bearer_access_token()
1290            .await;
1291
1292        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1293            // the client is configured without any OAuthSession, but this call does not require one.
1294            #[cfg(feature = "tracing")]
1295            tracing::debug!(
1296                "No client credentials found, but this call does not require authentication."
1297            );
1298        } else {
1299            local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
1300        }
1301    }
1302
1303    let local_var_req = local_var_req_builder.build()?;
1304    let local_var_resp = local_var_client.execute(local_var_req).await?;
1305
1306    let local_var_status = local_var_resp.status();
1307    let local_var_raw_content_type = local_var_resp
1308        .headers()
1309        .get("content-type")
1310        .and_then(|v| v.to_str().ok())
1311        .unwrap_or("application/octet-stream")
1312        .to_string();
1313    let local_var_content_type = super::ContentType::from(local_var_raw_content_type.as_str());
1314
1315    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1316        let local_var_content = local_var_resp.text().await?;
1317        match local_var_content_type {
1318            ContentType::Json => serde_path_to_error::deserialize(
1319                &mut serde_json::Deserializer::from_str(&local_var_content),
1320            )
1321            .map_err(Error::from),
1322            ContentType::Text => Err(Error::InvalidContentType {
1323                content_type: local_var_raw_content_type,
1324                return_type: "models::ListReservationsResponse",
1325            }),
1326            ContentType::Unsupported(unknown_type) => Err(Error::InvalidContentType {
1327                content_type: unknown_type,
1328                return_type: "models::ListReservationsResponse",
1329            }),
1330        }
1331    } else {
1332        let local_var_retry_delay =
1333            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1334        let local_var_content = local_var_resp.text().await?;
1335        let local_var_entity: Option<ListGroupReservationsError> =
1336            serde_json::from_str(&local_var_content).ok();
1337        let local_var_error = ResponseContent {
1338            status: local_var_status,
1339            content: local_var_content,
1340            entity: local_var_entity,
1341            retry_delay: local_var_retry_delay,
1342        };
1343        Err(Error::ResponseError(local_var_error))
1344    }
1345}
1346
1347/// List existing reservations for the requested group.  Available filter fields include:  * `startTime` - timestamp * `endTime` - timestamp * `createdTime` - timestamp * `price` - integer * `quantumProcessorId` - string  Available order fields include:  * `startTime` - timestamp * `endTime` - timestamp * `createdTime` - timestamp * `price` - integer
1348pub async fn list_group_reservations(
1349    configuration: &configuration::Configuration,
1350    group_name: &str,
1351    filter: Option<&str>,
1352    order: Option<&str>,
1353    page_size: Option<i64>,
1354    page_token: Option<&str>,
1355    show_deleted: Option<&str>,
1356) -> Result<models::ListReservationsResponse, Error<ListGroupReservationsError>> {
1357    let mut backoff = configuration.backoff.clone();
1358    let mut refreshed_credentials = false;
1359    let method = reqwest::Method::GET;
1360    loop {
1361        let result = list_group_reservations_inner(
1362            configuration,
1363            &mut backoff,
1364            group_name.clone(),
1365            filter.clone(),
1366            order.clone(),
1367            page_size.clone(),
1368            page_token.clone(),
1369            show_deleted.clone(),
1370        )
1371        .await;
1372
1373        match result {
1374            Ok(result) => return Ok(result),
1375            Err(Error::ResponseError(response)) => {
1376                if !refreshed_credentials
1377                    && matches!(
1378                        response.status,
1379                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1380                    )
1381                {
1382                    configuration.qcs_config.refresh().await?;
1383                    refreshed_credentials = true;
1384                    continue;
1385                } else if let Some(duration) = response.retry_delay {
1386                    tokio::time::sleep(duration).await;
1387                    continue;
1388                }
1389
1390                return Err(Error::ResponseError(response));
1391            }
1392            Err(Error::Reqwest(error)) => {
1393                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1394                    tokio::time::sleep(duration).await;
1395                    continue;
1396                }
1397
1398                return Err(Error::Reqwest(error));
1399            }
1400            Err(Error::Io(error)) => {
1401                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1402                    tokio::time::sleep(duration).await;
1403                    continue;
1404                }
1405
1406                return Err(Error::Io(error));
1407            }
1408            Err(error) => return Err(error),
1409        }
1410    }
1411}
1412async fn list_reservations_inner(
1413    configuration: &configuration::Configuration,
1414    backoff: &mut ExponentialBackoff,
1415    filter: Option<&str>,
1416    order: Option<&str>,
1417    page_size: Option<i64>,
1418    page_token: Option<&str>,
1419    show_deleted: Option<&str>,
1420    x_qcs_account_id: Option<&str>,
1421    x_qcs_account_type: Option<models::AccountType>,
1422) -> Result<models::ListReservationsResponse, Error<ListReservationsError>> {
1423    let local_var_configuration = configuration;
1424    // add a prefix to parameters to efficiently prevent name collisions
1425    let p_query_filter = filter;
1426    let p_query_order = order;
1427    let p_query_page_size = page_size;
1428    let p_query_page_token = page_token;
1429    let p_query_show_deleted = show_deleted;
1430    let p_header_x_qcs_account_id = x_qcs_account_id;
1431    let p_header_x_qcs_account_type = x_qcs_account_type;
1432
1433    let local_var_client = &local_var_configuration.client;
1434
1435    let local_var_uri_str = format!(
1436        "{}/v1/reservations",
1437        local_var_configuration.qcs_config.api_url()
1438    );
1439    let mut local_var_req_builder =
1440        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1441
1442    #[cfg(feature = "tracing")]
1443    {
1444        // Ignore parsing errors if the URL is invalid for some reason.
1445        // If it is invalid, it will turn up as an error later when actually making the request.
1446        let local_var_do_tracing = local_var_uri_str
1447            .parse::<::url::Url>()
1448            .ok()
1449            .is_none_or(|url| {
1450                configuration
1451                    .qcs_config
1452                    .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1453            });
1454
1455        if local_var_do_tracing {
1456            ::tracing::debug!(
1457                url=%local_var_uri_str,
1458                method="GET",
1459                "making list_reservations request",
1460            );
1461        }
1462    }
1463
1464    if let Some(ref local_var_str) = p_query_filter {
1465        local_var_req_builder =
1466            local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
1467    }
1468    if let Some(ref local_var_str) = p_query_order {
1469        local_var_req_builder =
1470            local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
1471    }
1472    if let Some(ref local_var_str) = p_query_page_size {
1473        local_var_req_builder =
1474            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
1475    }
1476    if let Some(ref local_var_str) = p_query_page_token {
1477        local_var_req_builder =
1478            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
1479    }
1480    if let Some(ref local_var_str) = p_query_show_deleted {
1481        local_var_req_builder =
1482            local_var_req_builder.query(&[("showDeleted", &local_var_str.to_string())]);
1483    }
1484    if let Some(local_var_param_value) = p_header_x_qcs_account_id {
1485        local_var_req_builder =
1486            local_var_req_builder.header("x-qcs-account-id", local_var_param_value.to_string());
1487    }
1488    if let Some(local_var_param_value) = p_header_x_qcs_account_type {
1489        local_var_req_builder =
1490            local_var_req_builder.header("x-qcs-account-type", local_var_param_value.to_string());
1491    }
1492
1493    // Use the QCS Bearer token if a client OAuthSession is present,
1494    // but do not require one when the security schema says it is optional.
1495    {
1496        use qcs_api_client_common::configuration::TokenError;
1497
1498        #[allow(
1499            clippy::nonminimal_bool,
1500            clippy::eq_op,
1501            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1502        )]
1503        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1504
1505        let token = local_var_configuration
1506            .qcs_config
1507            .get_bearer_access_token()
1508            .await;
1509
1510        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1511            // the client is configured without any OAuthSession, but this call does not require one.
1512            #[cfg(feature = "tracing")]
1513            tracing::debug!(
1514                "No client credentials found, but this call does not require authentication."
1515            );
1516        } else {
1517            local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
1518        }
1519    }
1520
1521    let local_var_req = local_var_req_builder.build()?;
1522    let local_var_resp = local_var_client.execute(local_var_req).await?;
1523
1524    let local_var_status = local_var_resp.status();
1525    let local_var_raw_content_type = local_var_resp
1526        .headers()
1527        .get("content-type")
1528        .and_then(|v| v.to_str().ok())
1529        .unwrap_or("application/octet-stream")
1530        .to_string();
1531    let local_var_content_type = super::ContentType::from(local_var_raw_content_type.as_str());
1532
1533    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1534        let local_var_content = local_var_resp.text().await?;
1535        match local_var_content_type {
1536            ContentType::Json => serde_path_to_error::deserialize(
1537                &mut serde_json::Deserializer::from_str(&local_var_content),
1538            )
1539            .map_err(Error::from),
1540            ContentType::Text => Err(Error::InvalidContentType {
1541                content_type: local_var_raw_content_type,
1542                return_type: "models::ListReservationsResponse",
1543            }),
1544            ContentType::Unsupported(unknown_type) => Err(Error::InvalidContentType {
1545                content_type: unknown_type,
1546                return_type: "models::ListReservationsResponse",
1547            }),
1548        }
1549    } else {
1550        let local_var_retry_delay =
1551            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1552        let local_var_content = local_var_resp.text().await?;
1553        let local_var_entity: Option<ListReservationsError> =
1554            serde_json::from_str(&local_var_content).ok();
1555        let local_var_error = ResponseContent {
1556            status: local_var_status,
1557            content: local_var_content,
1558            entity: local_var_entity,
1559            retry_delay: local_var_retry_delay,
1560        };
1561        Err(Error::ResponseError(local_var_error))
1562    }
1563}
1564
1565/// List existing reservations for the authenticated user, or a target user when specifying `X-QCS-ACCOUNT-ID` and `X-QCS-ACCOUNT-TYPE` headers.  Available filter fields include:  * `startTime` - timestamp * `endTime` - timestamp * `createdTime` - timestamp * `price` - integer * `cancelled` - boolean (deprecated, use `showDeleted` parameter) * `quantumProcessorId` - string  Available order fields include:  * `startTime` - timestamp * `endTime` - timestamp * `createdTime` - timestamp * `price` - integer
1566pub async fn list_reservations(
1567    configuration: &configuration::Configuration,
1568    filter: Option<&str>,
1569    order: Option<&str>,
1570    page_size: Option<i64>,
1571    page_token: Option<&str>,
1572    show_deleted: Option<&str>,
1573    x_qcs_account_id: Option<&str>,
1574    x_qcs_account_type: Option<models::AccountType>,
1575) -> Result<models::ListReservationsResponse, Error<ListReservationsError>> {
1576    let mut backoff = configuration.backoff.clone();
1577    let mut refreshed_credentials = false;
1578    let method = reqwest::Method::GET;
1579    loop {
1580        let result = list_reservations_inner(
1581            configuration,
1582            &mut backoff,
1583            filter.clone(),
1584            order.clone(),
1585            page_size.clone(),
1586            page_token.clone(),
1587            show_deleted.clone(),
1588            x_qcs_account_id.clone(),
1589            x_qcs_account_type.clone(),
1590        )
1591        .await;
1592
1593        match result {
1594            Ok(result) => return Ok(result),
1595            Err(Error::ResponseError(response)) => {
1596                if !refreshed_credentials
1597                    && matches!(
1598                        response.status,
1599                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1600                    )
1601                {
1602                    configuration.qcs_config.refresh().await?;
1603                    refreshed_credentials = true;
1604                    continue;
1605                } else if let Some(duration) = response.retry_delay {
1606                    tokio::time::sleep(duration).await;
1607                    continue;
1608                }
1609
1610                return Err(Error::ResponseError(response));
1611            }
1612            Err(Error::Reqwest(error)) => {
1613                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1614                    tokio::time::sleep(duration).await;
1615                    continue;
1616                }
1617
1618                return Err(Error::Reqwest(error));
1619            }
1620            Err(Error::Io(error)) => {
1621                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1622                    tokio::time::sleep(duration).await;
1623                    continue;
1624                }
1625
1626                return Err(Error::Io(error));
1627            }
1628            Err(error) => return Err(error),
1629        }
1630    }
1631}