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