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, Error};
26use crate::apis::ResponseContent;
27use ::qcs_api_client_common::backoff::{
28    duration_from_io_error, duration_from_reqwest_error, duration_from_response, ExponentialBackoff,
29};
30#[cfg(feature = "tracing")]
31use qcs_api_client_common::configuration::TokenRefresher;
32use reqwest::StatusCode;
33use serde::{Deserialize, Serialize};
34
35/// struct for typed errors of method [`create_reservation`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum CreateReservationError {
39    Status401(crate::models::Error),
40    Status402(crate::models::Error),
41    Status403(crate::models::Error),
42    Status409(crate::models::Error),
43    Status422(crate::models::Error),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`delete_reservation`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum DeleteReservationError {
51    Status401(crate::models::Error),
52    Status403(crate::models::Error),
53    Status404(crate::models::Error),
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`find_available_reservations`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum FindAvailableReservationsError {
61    Status401(crate::models::Error),
62    Status422(crate::models::Error),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`get_quantum_processor_calendar`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetQuantumProcessorCalendarError {
70    Status403(crate::models::Error),
71    Status404(crate::models::Error),
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`get_reservation`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum GetReservationError {
79    Status401(crate::models::Error),
80    Status403(crate::models::Error),
81    Status404(crate::models::Error),
82    UnknownValue(serde_json::Value),
83}
84
85/// struct for typed errors of method [`list_group_reservations`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum ListGroupReservationsError {
89    Status401(crate::models::Error),
90    Status422(crate::models::Error),
91    UnknownValue(serde_json::Value),
92}
93
94/// struct for typed errors of method [`list_reservations`]
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum ListReservationsError {
98    Status401(crate::models::Error),
99    Status422(crate::models::Error),
100    UnknownValue(serde_json::Value),
101}
102
103async fn create_reservation_inner(
104    configuration: &configuration::Configuration,
105    backoff: &mut ExponentialBackoff,
106    create_reservation_request: crate::models::CreateReservationRequest,
107    x_qcs_account_id: Option<&str>,
108    x_qcs_account_type: Option<crate::models::AccountType>,
109) -> Result<crate::models::Reservation, Error<CreateReservationError>> {
110    let local_var_configuration = configuration;
111
112    let local_var_client = &local_var_configuration.client;
113
114    let local_var_uri_str = format!(
115        "{}/v1/reservations",
116        local_var_configuration.qcs_config.api_url()
117    );
118    let mut local_var_req_builder =
119        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
120
121    #[cfg(feature = "tracing")]
122    {
123        // Ignore parsing errors if the URL is invalid for some reason.
124        // If it is invalid, it will turn up as an error later when actually making the request.
125        let local_var_do_tracing =
126            local_var_uri_str
127                .parse::<::url::Url>()
128                .ok()
129                .map_or(true, |url| {
130                    configuration
131                        .qcs_config
132                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
133                });
134
135        if local_var_do_tracing {
136            ::tracing::debug!(
137                url=%local_var_uri_str,
138                method="POST",
139                "making create_reservation request",
140            );
141        }
142    }
143
144    if let Some(local_var_param_value) = x_qcs_account_id {
145        local_var_req_builder =
146            local_var_req_builder.header("x-qcs-account-id", local_var_param_value.to_string());
147    }
148    if let Some(local_var_param_value) = x_qcs_account_type {
149        local_var_req_builder =
150            local_var_req_builder.header("x-qcs-account-type", local_var_param_value.to_string());
151    }
152
153    // Use the QCS Bearer token if a client OAuthSession is present,
154    // but do not require one when the security schema says it is optional.
155    {
156        use qcs_api_client_common::configuration::TokenError;
157
158        #[allow(
159            clippy::nonminimal_bool,
160            clippy::eq_op,
161            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
162        )]
163        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
164
165        let token = local_var_configuration
166            .qcs_config
167            .get_bearer_access_token()
168            .await;
169
170        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
171            // the client is configured without any OAuthSession, but this call does not require one.
172            #[cfg(feature = "tracing")]
173            tracing::debug!(
174                "No client credentials found, but this call does not require authentication."
175            );
176        } else {
177            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
178        }
179    }
180
181    local_var_req_builder = local_var_req_builder.json(&create_reservation_request);
182
183    let local_var_req = local_var_req_builder.build()?;
184    let local_var_resp = local_var_client.execute(local_var_req).await?;
185
186    let local_var_status = local_var_resp.status();
187
188    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
189        let local_var_content = local_var_resp.text().await?;
190        serde_json::from_str(&local_var_content).map_err(Error::from)
191    } else {
192        let local_var_retry_delay =
193            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
194        let local_var_content = local_var_resp.text().await?;
195        let local_var_entity: Option<CreateReservationError> =
196            serde_json::from_str(&local_var_content).ok();
197        let local_var_error = ResponseContent {
198            status: local_var_status,
199            content: local_var_content,
200            entity: local_var_entity,
201            retry_delay: local_var_retry_delay,
202        };
203        Err(Error::ResponseError(local_var_error))
204    }
205}
206
207/// 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.
208pub async fn create_reservation(
209    configuration: &configuration::Configuration,
210    create_reservation_request: crate::models::CreateReservationRequest,
211    x_qcs_account_id: Option<&str>,
212    x_qcs_account_type: Option<crate::models::AccountType>,
213) -> Result<crate::models::Reservation, Error<CreateReservationError>> {
214    let mut backoff = configuration.backoff.clone();
215    let mut refreshed_credentials = false;
216    let method = reqwest::Method::POST;
217    loop {
218        let result = create_reservation_inner(
219            configuration,
220            &mut backoff,
221            create_reservation_request.clone(),
222            x_qcs_account_id.clone(),
223            x_qcs_account_type.clone(),
224        )
225        .await;
226
227        match result {
228            Ok(result) => return Ok(result),
229            Err(Error::ResponseError(response)) => {
230                if !refreshed_credentials
231                    && matches!(
232                        response.status,
233                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
234                    )
235                {
236                    configuration.qcs_config.refresh().await?;
237                    refreshed_credentials = true;
238                    continue;
239                } else if let Some(duration) = response.retry_delay {
240                    tokio::time::sleep(duration).await;
241                    continue;
242                }
243
244                return Err(Error::ResponseError(response));
245            }
246            Err(Error::Reqwest(error)) => {
247                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
248                    tokio::time::sleep(duration).await;
249                    continue;
250                }
251
252                return Err(Error::Reqwest(error));
253            }
254            Err(Error::Io(error)) => {
255                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
256                    tokio::time::sleep(duration).await;
257                    continue;
258                }
259
260                return Err(Error::Io(error));
261            }
262            Err(error) => return Err(error),
263        }
264    }
265}
266async fn delete_reservation_inner(
267    configuration: &configuration::Configuration,
268    backoff: &mut ExponentialBackoff,
269    reservation_id: i64,
270) -> Result<crate::models::Reservation, Error<DeleteReservationError>> {
271    let local_var_configuration = configuration;
272
273    let local_var_client = &local_var_configuration.client;
274
275    let local_var_uri_str = format!(
276        "{}/v1/reservations/{reservationId}",
277        local_var_configuration.qcs_config.api_url(),
278        reservationId = reservation_id
279    );
280    let mut local_var_req_builder =
281        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
282
283    #[cfg(feature = "tracing")]
284    {
285        // Ignore parsing errors if the URL is invalid for some reason.
286        // If it is invalid, it will turn up as an error later when actually making the request.
287        let local_var_do_tracing =
288            local_var_uri_str
289                .parse::<::url::Url>()
290                .ok()
291                .map_or(true, |url| {
292                    configuration
293                        .qcs_config
294                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
295                });
296
297        if local_var_do_tracing {
298            ::tracing::debug!(
299                url=%local_var_uri_str,
300                method="DELETE",
301                "making delete_reservation request",
302            );
303        }
304    }
305
306    // Use the QCS Bearer token if a client OAuthSession is present,
307    // but do not require one when the security schema says it is optional.
308    {
309        use qcs_api_client_common::configuration::TokenError;
310
311        #[allow(
312            clippy::nonminimal_bool,
313            clippy::eq_op,
314            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
315        )]
316        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
317
318        let token = local_var_configuration
319            .qcs_config
320            .get_bearer_access_token()
321            .await;
322
323        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
324            // the client is configured without any OAuthSession, but this call does not require one.
325            #[cfg(feature = "tracing")]
326            tracing::debug!(
327                "No client credentials found, but this call does not require authentication."
328            );
329        } else {
330            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
331        }
332    }
333
334    let local_var_req = local_var_req_builder.build()?;
335    let local_var_resp = local_var_client.execute(local_var_req).await?;
336
337    let local_var_status = local_var_resp.status();
338
339    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
340        let local_var_content = local_var_resp.text().await?;
341        serde_json::from_str(&local_var_content).map_err(Error::from)
342    } else {
343        let local_var_retry_delay =
344            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
345        let local_var_content = local_var_resp.text().await?;
346        let local_var_entity: Option<DeleteReservationError> =
347            serde_json::from_str(&local_var_content).ok();
348        let local_var_error = ResponseContent {
349            status: local_var_status,
350            content: local_var_content,
351            entity: local_var_entity,
352            retry_delay: local_var_retry_delay,
353        };
354        Err(Error::ResponseError(local_var_error))
355    }
356}
357
358/// Cancel an existing reservation for the user.
359pub async fn delete_reservation(
360    configuration: &configuration::Configuration,
361    reservation_id: i64,
362) -> Result<crate::models::Reservation, Error<DeleteReservationError>> {
363    let mut backoff = configuration.backoff.clone();
364    let mut refreshed_credentials = false;
365    let method = reqwest::Method::DELETE;
366    loop {
367        let result =
368            delete_reservation_inner(configuration, &mut backoff, reservation_id.clone()).await;
369
370        match result {
371            Ok(result) => return Ok(result),
372            Err(Error::ResponseError(response)) => {
373                if !refreshed_credentials
374                    && matches!(
375                        response.status,
376                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
377                    )
378                {
379                    configuration.qcs_config.refresh().await?;
380                    refreshed_credentials = true;
381                    continue;
382                } else if let Some(duration) = response.retry_delay {
383                    tokio::time::sleep(duration).await;
384                    continue;
385                }
386
387                return Err(Error::ResponseError(response));
388            }
389            Err(Error::Reqwest(error)) => {
390                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
391                    tokio::time::sleep(duration).await;
392                    continue;
393                }
394
395                return Err(Error::Reqwest(error));
396            }
397            Err(Error::Io(error)) => {
398                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
399                    tokio::time::sleep(duration).await;
400                    continue;
401                }
402
403                return Err(Error::Io(error));
404            }
405            Err(error) => return Err(error),
406        }
407    }
408}
409async fn find_available_reservations_inner(
410    configuration: &configuration::Configuration,
411    backoff: &mut ExponentialBackoff,
412    quantum_processor_id: &str,
413    start_time_from: String,
414    duration: &str,
415    page_size: Option<i64>,
416    page_token: Option<&str>,
417) -> Result<crate::models::FindAvailableReservationsResponse, Error<FindAvailableReservationsError>>
418{
419    let local_var_configuration = configuration;
420
421    let local_var_client = &local_var_configuration.client;
422
423    let local_var_uri_str = format!(
424        "{}/v1/reservations:findAvailable",
425        local_var_configuration.qcs_config.api_url()
426    );
427    let mut local_var_req_builder =
428        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
429
430    #[cfg(feature = "tracing")]
431    {
432        // Ignore parsing errors if the URL is invalid for some reason.
433        // If it is invalid, it will turn up as an error later when actually making the request.
434        let local_var_do_tracing =
435            local_var_uri_str
436                .parse::<::url::Url>()
437                .ok()
438                .map_or(true, |url| {
439                    configuration
440                        .qcs_config
441                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
442                });
443
444        if local_var_do_tracing {
445            ::tracing::debug!(
446                url=%local_var_uri_str,
447                method="GET",
448                "making find_available_reservations request",
449            );
450        }
451    }
452
453    if let Some(ref local_var_str) = page_size {
454        local_var_req_builder =
455            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
456    }
457    if let Some(ref local_var_str) = page_token {
458        local_var_req_builder =
459            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
460    }
461    local_var_req_builder =
462        local_var_req_builder.query(&[("quantumProcessorId", &quantum_processor_id.to_string())]);
463    local_var_req_builder =
464        local_var_req_builder.query(&[("startTimeFrom", &start_time_from.to_string())]);
465    local_var_req_builder = local_var_req_builder.query(&[("duration", &duration.to_string())]);
466
467    // Use the QCS Bearer token if a client OAuthSession is present,
468    // but do not require one when the security schema says it is optional.
469    {
470        use qcs_api_client_common::configuration::TokenError;
471
472        #[allow(
473            clippy::nonminimal_bool,
474            clippy::eq_op,
475            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
476        )]
477        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
478
479        let token = local_var_configuration
480            .qcs_config
481            .get_bearer_access_token()
482            .await;
483
484        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
485            // the client is configured without any OAuthSession, but this call does not require one.
486            #[cfg(feature = "tracing")]
487            tracing::debug!(
488                "No client credentials found, but this call does not require authentication."
489            );
490        } else {
491            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
492        }
493    }
494
495    let local_var_req = local_var_req_builder.build()?;
496    let local_var_resp = local_var_client.execute(local_var_req).await?;
497
498    let local_var_status = local_var_resp.status();
499
500    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
501        let local_var_content = local_var_resp.text().await?;
502        serde_json::from_str(&local_var_content).map_err(Error::from)
503    } else {
504        let local_var_retry_delay =
505            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
506        let local_var_content = local_var_resp.text().await?;
507        let local_var_entity: Option<FindAvailableReservationsError> =
508            serde_json::from_str(&local_var_content).ok();
509        let local_var_error = ResponseContent {
510            status: local_var_status,
511            content: local_var_content,
512            entity: local_var_entity,
513            retry_delay: local_var_retry_delay,
514        };
515        Err(Error::ResponseError(local_var_error))
516    }
517}
518
519/// List currently available reservations on the requested Rigetti quantum computer.
520pub async fn find_available_reservations(
521    configuration: &configuration::Configuration,
522    quantum_processor_id: &str,
523    start_time_from: String,
524    duration: &str,
525    page_size: Option<i64>,
526    page_token: Option<&str>,
527) -> Result<crate::models::FindAvailableReservationsResponse, Error<FindAvailableReservationsError>>
528{
529    let mut backoff = configuration.backoff.clone();
530    let mut refreshed_credentials = false;
531    let method = reqwest::Method::GET;
532    loop {
533        let result = find_available_reservations_inner(
534            configuration,
535            &mut backoff,
536            quantum_processor_id.clone(),
537            start_time_from.clone(),
538            duration.clone(),
539            page_size.clone(),
540            page_token.clone(),
541        )
542        .await;
543
544        match result {
545            Ok(result) => return Ok(result),
546            Err(Error::ResponseError(response)) => {
547                if !refreshed_credentials
548                    && matches!(
549                        response.status,
550                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
551                    )
552                {
553                    configuration.qcs_config.refresh().await?;
554                    refreshed_credentials = true;
555                    continue;
556                } else if let Some(duration) = response.retry_delay {
557                    tokio::time::sleep(duration).await;
558                    continue;
559                }
560
561                return Err(Error::ResponseError(response));
562            }
563            Err(Error::Reqwest(error)) => {
564                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
565                    tokio::time::sleep(duration).await;
566                    continue;
567                }
568
569                return Err(Error::Reqwest(error));
570            }
571            Err(Error::Io(error)) => {
572                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
573                    tokio::time::sleep(duration).await;
574                    continue;
575                }
576
577                return Err(Error::Io(error));
578            }
579            Err(error) => return Err(error),
580        }
581    }
582}
583async fn get_quantum_processor_calendar_inner(
584    configuration: &configuration::Configuration,
585    backoff: &mut ExponentialBackoff,
586    quantum_processor_id: &str,
587) -> Result<crate::models::QuantumProcessorCalendar, Error<GetQuantumProcessorCalendarError>> {
588    let local_var_configuration = configuration;
589
590    let local_var_client = &local_var_configuration.client;
591
592    let local_var_uri_str = format!(
593        "{}/v1/calendars/{quantumProcessorId}",
594        local_var_configuration.qcs_config.api_url(),
595        quantumProcessorId = crate::apis::urlencode(quantum_processor_id)
596    );
597    let mut local_var_req_builder =
598        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
599
600    #[cfg(feature = "tracing")]
601    {
602        // Ignore parsing errors if the URL is invalid for some reason.
603        // If it is invalid, it will turn up as an error later when actually making the request.
604        let local_var_do_tracing =
605            local_var_uri_str
606                .parse::<::url::Url>()
607                .ok()
608                .map_or(true, |url| {
609                    configuration
610                        .qcs_config
611                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
612                });
613
614        if local_var_do_tracing {
615            ::tracing::debug!(
616                url=%local_var_uri_str,
617                method="GET",
618                "making get_quantum_processor_calendar request",
619            );
620        }
621    }
622
623    // Use the QCS Bearer token if a client OAuthSession is present,
624    // but do not require one when the security schema says it is optional.
625    {
626        use qcs_api_client_common::configuration::TokenError;
627
628        #[allow(
629            clippy::nonminimal_bool,
630            clippy::eq_op,
631            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
632        )]
633        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
634
635        let token = local_var_configuration
636            .qcs_config
637            .get_bearer_access_token()
638            .await;
639
640        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
641            // the client is configured without any OAuthSession, but this call does not require one.
642            #[cfg(feature = "tracing")]
643            tracing::debug!(
644                "No client credentials found, but this call does not require authentication."
645            );
646        } else {
647            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
648        }
649    }
650
651    let local_var_req = local_var_req_builder.build()?;
652    let local_var_resp = local_var_client.execute(local_var_req).await?;
653
654    let local_var_status = local_var_resp.status();
655
656    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
657        let local_var_content = local_var_resp.text().await?;
658        serde_json::from_str(&local_var_content).map_err(Error::from)
659    } else {
660        let local_var_retry_delay =
661            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
662        let local_var_content = local_var_resp.text().await?;
663        let local_var_entity: Option<GetQuantumProcessorCalendarError> =
664            serde_json::from_str(&local_var_content).ok();
665        let local_var_error = ResponseContent {
666            status: local_var_status,
667            content: local_var_content,
668            entity: local_var_entity,
669            retry_delay: local_var_retry_delay,
670        };
671        Err(Error::ResponseError(local_var_error))
672    }
673}
674
675/// Get calendar details for the requested quantum processor.
676pub async fn get_quantum_processor_calendar(
677    configuration: &configuration::Configuration,
678    quantum_processor_id: &str,
679) -> Result<crate::models::QuantumProcessorCalendar, Error<GetQuantumProcessorCalendarError>> {
680    let mut backoff = configuration.backoff.clone();
681    let mut refreshed_credentials = false;
682    let method = reqwest::Method::GET;
683    loop {
684        let result = get_quantum_processor_calendar_inner(
685            configuration,
686            &mut backoff,
687            quantum_processor_id.clone(),
688        )
689        .await;
690
691        match result {
692            Ok(result) => return Ok(result),
693            Err(Error::ResponseError(response)) => {
694                if !refreshed_credentials
695                    && matches!(
696                        response.status,
697                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
698                    )
699                {
700                    configuration.qcs_config.refresh().await?;
701                    refreshed_credentials = true;
702                    continue;
703                } else if let Some(duration) = response.retry_delay {
704                    tokio::time::sleep(duration).await;
705                    continue;
706                }
707
708                return Err(Error::ResponseError(response));
709            }
710            Err(Error::Reqwest(error)) => {
711                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
712                    tokio::time::sleep(duration).await;
713                    continue;
714                }
715
716                return Err(Error::Reqwest(error));
717            }
718            Err(Error::Io(error)) => {
719                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
720                    tokio::time::sleep(duration).await;
721                    continue;
722                }
723
724                return Err(Error::Io(error));
725            }
726            Err(error) => return Err(error),
727        }
728    }
729}
730async fn get_reservation_inner(
731    configuration: &configuration::Configuration,
732    backoff: &mut ExponentialBackoff,
733    reservation_id: i64,
734) -> Result<crate::models::Reservation, Error<GetReservationError>> {
735    let local_var_configuration = configuration;
736
737    let local_var_client = &local_var_configuration.client;
738
739    let local_var_uri_str = format!(
740        "{}/v1/reservations/{reservationId}",
741        local_var_configuration.qcs_config.api_url(),
742        reservationId = reservation_id
743    );
744    let mut local_var_req_builder =
745        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
746
747    #[cfg(feature = "tracing")]
748    {
749        // Ignore parsing errors if the URL is invalid for some reason.
750        // If it is invalid, it will turn up as an error later when actually making the request.
751        let local_var_do_tracing =
752            local_var_uri_str
753                .parse::<::url::Url>()
754                .ok()
755                .map_or(true, |url| {
756                    configuration
757                        .qcs_config
758                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
759                });
760
761        if local_var_do_tracing {
762            ::tracing::debug!(
763                url=%local_var_uri_str,
764                method="GET",
765                "making get_reservation request",
766            );
767        }
768    }
769
770    // Use the QCS Bearer token if a client OAuthSession is present,
771    // but do not require one when the security schema says it is optional.
772    {
773        use qcs_api_client_common::configuration::TokenError;
774
775        #[allow(
776            clippy::nonminimal_bool,
777            clippy::eq_op,
778            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
779        )]
780        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
781
782        let token = local_var_configuration
783            .qcs_config
784            .get_bearer_access_token()
785            .await;
786
787        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
788            // the client is configured without any OAuthSession, but this call does not require one.
789            #[cfg(feature = "tracing")]
790            tracing::debug!(
791                "No client credentials found, but this call does not require authentication."
792            );
793        } else {
794            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
795        }
796    }
797
798    let local_var_req = local_var_req_builder.build()?;
799    let local_var_resp = local_var_client.execute(local_var_req).await?;
800
801    let local_var_status = local_var_resp.status();
802
803    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
804        let local_var_content = local_var_resp.text().await?;
805        serde_json::from_str(&local_var_content).map_err(Error::from)
806    } else {
807        let local_var_retry_delay =
808            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
809        let local_var_content = local_var_resp.text().await?;
810        let local_var_entity: Option<GetReservationError> =
811            serde_json::from_str(&local_var_content).ok();
812        let local_var_error = ResponseContent {
813            status: local_var_status,
814            content: local_var_content,
815            entity: local_var_entity,
816            retry_delay: local_var_retry_delay,
817        };
818        Err(Error::ResponseError(local_var_error))
819    }
820}
821
822/// Find an existing reservation by ID.
823pub async fn get_reservation(
824    configuration: &configuration::Configuration,
825    reservation_id: i64,
826) -> Result<crate::models::Reservation, Error<GetReservationError>> {
827    let mut backoff = configuration.backoff.clone();
828    let mut refreshed_credentials = false;
829    let method = reqwest::Method::GET;
830    loop {
831        let result =
832            get_reservation_inner(configuration, &mut backoff, reservation_id.clone()).await;
833
834        match result {
835            Ok(result) => return Ok(result),
836            Err(Error::ResponseError(response)) => {
837                if !refreshed_credentials
838                    && matches!(
839                        response.status,
840                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
841                    )
842                {
843                    configuration.qcs_config.refresh().await?;
844                    refreshed_credentials = true;
845                    continue;
846                } else if let Some(duration) = response.retry_delay {
847                    tokio::time::sleep(duration).await;
848                    continue;
849                }
850
851                return Err(Error::ResponseError(response));
852            }
853            Err(Error::Reqwest(error)) => {
854                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
855                    tokio::time::sleep(duration).await;
856                    continue;
857                }
858
859                return Err(Error::Reqwest(error));
860            }
861            Err(Error::Io(error)) => {
862                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
863                    tokio::time::sleep(duration).await;
864                    continue;
865                }
866
867                return Err(Error::Io(error));
868            }
869            Err(error) => return Err(error),
870        }
871    }
872}
873async fn list_group_reservations_inner(
874    configuration: &configuration::Configuration,
875    backoff: &mut ExponentialBackoff,
876    group_name: &str,
877    filter: Option<&str>,
878    order: Option<&str>,
879    page_size: Option<i64>,
880    page_token: Option<&str>,
881    show_deleted: Option<&str>,
882) -> Result<crate::models::ListReservationsResponse, Error<ListGroupReservationsError>> {
883    let local_var_configuration = configuration;
884
885    let local_var_client = &local_var_configuration.client;
886
887    let local_var_uri_str = format!(
888        "{}/v1/groups/{groupName}/reservations",
889        local_var_configuration.qcs_config.api_url(),
890        groupName = crate::apis::urlencode(group_name)
891    );
892    let mut local_var_req_builder =
893        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
894
895    #[cfg(feature = "tracing")]
896    {
897        // Ignore parsing errors if the URL is invalid for some reason.
898        // If it is invalid, it will turn up as an error later when actually making the request.
899        let local_var_do_tracing =
900            local_var_uri_str
901                .parse::<::url::Url>()
902                .ok()
903                .map_or(true, |url| {
904                    configuration
905                        .qcs_config
906                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
907                });
908
909        if local_var_do_tracing {
910            ::tracing::debug!(
911                url=%local_var_uri_str,
912                method="GET",
913                "making list_group_reservations request",
914            );
915        }
916    }
917
918    if let Some(ref local_var_str) = filter {
919        local_var_req_builder =
920            local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
921    }
922    if let Some(ref local_var_str) = order {
923        local_var_req_builder =
924            local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
925    }
926    if let Some(ref local_var_str) = page_size {
927        local_var_req_builder =
928            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
929    }
930    if let Some(ref local_var_str) = page_token {
931        local_var_req_builder =
932            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
933    }
934    if let Some(ref local_var_str) = show_deleted {
935        local_var_req_builder =
936            local_var_req_builder.query(&[("showDeleted", &local_var_str.to_string())]);
937    }
938
939    // Use the QCS Bearer token if a client OAuthSession is present,
940    // but do not require one when the security schema says it is optional.
941    {
942        use qcs_api_client_common::configuration::TokenError;
943
944        #[allow(
945            clippy::nonminimal_bool,
946            clippy::eq_op,
947            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
948        )]
949        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
950
951        let token = local_var_configuration
952            .qcs_config
953            .get_bearer_access_token()
954            .await;
955
956        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
957            // the client is configured without any OAuthSession, but this call does not require one.
958            #[cfg(feature = "tracing")]
959            tracing::debug!(
960                "No client credentials found, but this call does not require authentication."
961            );
962        } else {
963            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
964        }
965    }
966
967    let local_var_req = local_var_req_builder.build()?;
968    let local_var_resp = local_var_client.execute(local_var_req).await?;
969
970    let local_var_status = local_var_resp.status();
971
972    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
973        let local_var_content = local_var_resp.text().await?;
974        serde_json::from_str(&local_var_content).map_err(Error::from)
975    } else {
976        let local_var_retry_delay =
977            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
978        let local_var_content = local_var_resp.text().await?;
979        let local_var_entity: Option<ListGroupReservationsError> =
980            serde_json::from_str(&local_var_content).ok();
981        let local_var_error = ResponseContent {
982            status: local_var_status,
983            content: local_var_content,
984            entity: local_var_entity,
985            retry_delay: local_var_retry_delay,
986        };
987        Err(Error::ResponseError(local_var_error))
988    }
989}
990
991/// 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
992pub async fn list_group_reservations(
993    configuration: &configuration::Configuration,
994    group_name: &str,
995    filter: Option<&str>,
996    order: Option<&str>,
997    page_size: Option<i64>,
998    page_token: Option<&str>,
999    show_deleted: Option<&str>,
1000) -> Result<crate::models::ListReservationsResponse, Error<ListGroupReservationsError>> {
1001    let mut backoff = configuration.backoff.clone();
1002    let mut refreshed_credentials = false;
1003    let method = reqwest::Method::GET;
1004    loop {
1005        let result = list_group_reservations_inner(
1006            configuration,
1007            &mut backoff,
1008            group_name.clone(),
1009            filter.clone(),
1010            order.clone(),
1011            page_size.clone(),
1012            page_token.clone(),
1013            show_deleted.clone(),
1014        )
1015        .await;
1016
1017        match result {
1018            Ok(result) => return Ok(result),
1019            Err(Error::ResponseError(response)) => {
1020                if !refreshed_credentials
1021                    && matches!(
1022                        response.status,
1023                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1024                    )
1025                {
1026                    configuration.qcs_config.refresh().await?;
1027                    refreshed_credentials = true;
1028                    continue;
1029                } else if let Some(duration) = response.retry_delay {
1030                    tokio::time::sleep(duration).await;
1031                    continue;
1032                }
1033
1034                return Err(Error::ResponseError(response));
1035            }
1036            Err(Error::Reqwest(error)) => {
1037                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1038                    tokio::time::sleep(duration).await;
1039                    continue;
1040                }
1041
1042                return Err(Error::Reqwest(error));
1043            }
1044            Err(Error::Io(error)) => {
1045                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1046                    tokio::time::sleep(duration).await;
1047                    continue;
1048                }
1049
1050                return Err(Error::Io(error));
1051            }
1052            Err(error) => return Err(error),
1053        }
1054    }
1055}
1056async fn list_reservations_inner(
1057    configuration: &configuration::Configuration,
1058    backoff: &mut ExponentialBackoff,
1059    filter: Option<&str>,
1060    order: Option<&str>,
1061    page_size: Option<i64>,
1062    page_token: Option<&str>,
1063    show_deleted: Option<&str>,
1064    x_qcs_account_id: Option<&str>,
1065    x_qcs_account_type: Option<crate::models::AccountType>,
1066) -> Result<crate::models::ListReservationsResponse, Error<ListReservationsError>> {
1067    let local_var_configuration = configuration;
1068
1069    let local_var_client = &local_var_configuration.client;
1070
1071    let local_var_uri_str = format!(
1072        "{}/v1/reservations",
1073        local_var_configuration.qcs_config.api_url()
1074    );
1075    let mut local_var_req_builder =
1076        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1077
1078    #[cfg(feature = "tracing")]
1079    {
1080        // Ignore parsing errors if the URL is invalid for some reason.
1081        // If it is invalid, it will turn up as an error later when actually making the request.
1082        let local_var_do_tracing =
1083            local_var_uri_str
1084                .parse::<::url::Url>()
1085                .ok()
1086                .map_or(true, |url| {
1087                    configuration
1088                        .qcs_config
1089                        .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1090                });
1091
1092        if local_var_do_tracing {
1093            ::tracing::debug!(
1094                url=%local_var_uri_str,
1095                method="GET",
1096                "making list_reservations request",
1097            );
1098        }
1099    }
1100
1101    if let Some(ref local_var_str) = filter {
1102        local_var_req_builder =
1103            local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
1104    }
1105    if let Some(ref local_var_str) = order {
1106        local_var_req_builder =
1107            local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
1108    }
1109    if let Some(ref local_var_str) = page_size {
1110        local_var_req_builder =
1111            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
1112    }
1113    if let Some(ref local_var_str) = page_token {
1114        local_var_req_builder =
1115            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
1116    }
1117    if let Some(ref local_var_str) = show_deleted {
1118        local_var_req_builder =
1119            local_var_req_builder.query(&[("showDeleted", &local_var_str.to_string())]);
1120    }
1121    if let Some(local_var_param_value) = x_qcs_account_id {
1122        local_var_req_builder =
1123            local_var_req_builder.header("x-qcs-account-id", local_var_param_value.to_string());
1124    }
1125    if let Some(local_var_param_value) = x_qcs_account_type {
1126        local_var_req_builder =
1127            local_var_req_builder.header("x-qcs-account-type", local_var_param_value.to_string());
1128    }
1129
1130    // Use the QCS Bearer token if a client OAuthSession is present,
1131    // but do not require one when the security schema says it is optional.
1132    {
1133        use qcs_api_client_common::configuration::TokenError;
1134
1135        #[allow(
1136            clippy::nonminimal_bool,
1137            clippy::eq_op,
1138            reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1139        )]
1140        let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1141
1142        let token = local_var_configuration
1143            .qcs_config
1144            .get_bearer_access_token()
1145            .await;
1146
1147        if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1148            // the client is configured without any OAuthSession, but this call does not require one.
1149            #[cfg(feature = "tracing")]
1150            tracing::debug!(
1151                "No client credentials found, but this call does not require authentication."
1152            );
1153        } else {
1154            local_var_req_builder = local_var_req_builder.bearer_auth(token?);
1155        }
1156    }
1157
1158    let local_var_req = local_var_req_builder.build()?;
1159    let local_var_resp = local_var_client.execute(local_var_req).await?;
1160
1161    let local_var_status = local_var_resp.status();
1162
1163    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1164        let local_var_content = local_var_resp.text().await?;
1165        serde_json::from_str(&local_var_content).map_err(Error::from)
1166    } else {
1167        let local_var_retry_delay =
1168            duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1169        let local_var_content = local_var_resp.text().await?;
1170        let local_var_entity: Option<ListReservationsError> =
1171            serde_json::from_str(&local_var_content).ok();
1172        let local_var_error = ResponseContent {
1173            status: local_var_status,
1174            content: local_var_content,
1175            entity: local_var_entity,
1176            retry_delay: local_var_retry_delay,
1177        };
1178        Err(Error::ResponseError(local_var_error))
1179    }
1180}
1181
1182/// 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
1183pub async fn list_reservations(
1184    configuration: &configuration::Configuration,
1185    filter: Option<&str>,
1186    order: Option<&str>,
1187    page_size: Option<i64>,
1188    page_token: Option<&str>,
1189    show_deleted: Option<&str>,
1190    x_qcs_account_id: Option<&str>,
1191    x_qcs_account_type: Option<crate::models::AccountType>,
1192) -> Result<crate::models::ListReservationsResponse, Error<ListReservationsError>> {
1193    let mut backoff = configuration.backoff.clone();
1194    let mut refreshed_credentials = false;
1195    let method = reqwest::Method::GET;
1196    loop {
1197        let result = list_reservations_inner(
1198            configuration,
1199            &mut backoff,
1200            filter.clone(),
1201            order.clone(),
1202            page_size.clone(),
1203            page_token.clone(),
1204            show_deleted.clone(),
1205            x_qcs_account_id.clone(),
1206            x_qcs_account_type.clone(),
1207        )
1208        .await;
1209
1210        match result {
1211            Ok(result) => return Ok(result),
1212            Err(Error::ResponseError(response)) => {
1213                if !refreshed_credentials
1214                    && matches!(
1215                        response.status,
1216                        StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1217                    )
1218                {
1219                    configuration.qcs_config.refresh().await?;
1220                    refreshed_credentials = true;
1221                    continue;
1222                } else if let Some(duration) = response.retry_delay {
1223                    tokio::time::sleep(duration).await;
1224                    continue;
1225                }
1226
1227                return Err(Error::ResponseError(response));
1228            }
1229            Err(Error::Reqwest(error)) => {
1230                if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1231                    tokio::time::sleep(duration).await;
1232                    continue;
1233                }
1234
1235                return Err(Error::Reqwest(error));
1236            }
1237            Err(Error::Io(error)) => {
1238                if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1239                    tokio::time::sleep(duration).await;
1240                    continue;
1241                }
1242
1243                return Err(Error::Io(error));
1244            }
1245            Err(error) => return Err(error),
1246        }
1247    }
1248}