1use 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#[cfg(feature = "clap")]
36#[allow(unused, reason = "not used in all templates, but required in some")]
37use ::{miette::IntoDiagnostic as _, qcs_api_client_common::clap_utils::JsonMaybeStdin};
38
39#[cfg(feature = "clap")]
41#[derive(Debug, clap::Args)]
42pub struct CreateReservationClapParams {
43 pub create_reservation_request: JsonMaybeStdin<crate::models::CreateReservationRequest>,
44 #[arg(long)]
46 pub x_qcs_account_id: Option<String>,
47 #[arg(long)]
49 pub x_qcs_account_type: Option<crate::models::AccountType>,
50}
51
52#[cfg(feature = "clap")]
53impl CreateReservationClapParams {
54 pub async fn execute(
55 self,
56 configuration: &configuration::Configuration,
57 ) -> Result<crate::models::Reservation, miette::Error> {
58 let request = self.create_reservation_request.into_inner().into_inner();
59
60 create_reservation(
61 configuration,
62 request,
63 self.x_qcs_account_id.as_deref(),
64 self.x_qcs_account_type,
65 )
66 .await
67 .into_diagnostic()
68 }
69}
70
71#[cfg(feature = "clap")]
73#[derive(Debug, clap::Args)]
74pub struct DeleteReservationClapParams {
75 #[arg(long)]
76 pub reservation_id: i64,
77}
78
79#[cfg(feature = "clap")]
80impl DeleteReservationClapParams {
81 pub async fn execute(
82 self,
83 configuration: &configuration::Configuration,
84 ) -> Result<crate::models::Reservation, miette::Error> {
85 delete_reservation(configuration, self.reservation_id)
86 .await
87 .into_diagnostic()
88 }
89}
90
91#[cfg(feature = "clap")]
93#[derive(Debug, clap::Args)]
94pub struct FindAvailableReservationsClapParams {
95 #[arg(long)]
96 pub quantum_processor_id: String,
97 #[arg(long)]
98 pub start_time_from: String,
99 #[arg(long)]
100 pub duration: String,
101 #[arg(long)]
102 pub page_size: Option<i64>,
103 #[arg(long)]
105 pub page_token: Option<String>,
106}
107
108#[cfg(feature = "clap")]
109impl FindAvailableReservationsClapParams {
110 pub async fn execute(
111 self,
112 configuration: &configuration::Configuration,
113 ) -> Result<crate::models::FindAvailableReservationsResponse, miette::Error> {
114 find_available_reservations(
115 configuration,
116 self.quantum_processor_id.as_str(),
117 self.start_time_from,
118 self.duration.as_str(),
119 self.page_size,
120 self.page_token.as_deref(),
121 )
122 .await
123 .into_diagnostic()
124 }
125}
126
127#[cfg(feature = "clap")]
129#[derive(Debug, clap::Args)]
130pub struct GetQuantumProcessorCalendarClapParams {
131 #[arg(long)]
132 pub quantum_processor_id: String,
133}
134
135#[cfg(feature = "clap")]
136impl GetQuantumProcessorCalendarClapParams {
137 pub async fn execute(
138 self,
139 configuration: &configuration::Configuration,
140 ) -> Result<crate::models::QuantumProcessorCalendar, miette::Error> {
141 get_quantum_processor_calendar(configuration, self.quantum_processor_id.as_str())
142 .await
143 .into_diagnostic()
144 }
145}
146
147#[cfg(feature = "clap")]
149#[derive(Debug, clap::Args)]
150pub struct GetReservationClapParams {
151 #[arg(long)]
152 pub reservation_id: i64,
153}
154
155#[cfg(feature = "clap")]
156impl GetReservationClapParams {
157 pub async fn execute(
158 self,
159 configuration: &configuration::Configuration,
160 ) -> Result<crate::models::Reservation, miette::Error> {
161 get_reservation(configuration, self.reservation_id)
162 .await
163 .into_diagnostic()
164 }
165}
166
167#[cfg(feature = "clap")]
169#[derive(Debug, clap::Args)]
170pub struct ListGroupReservationsClapParams {
171 #[arg(long)]
173 pub group_name: String,
174 #[arg(long)]
175 pub filter: Option<String>,
176 #[arg(long)]
177 pub order: Option<String>,
178 #[arg(long)]
179 pub page_size: Option<i64>,
180 #[arg(long)]
182 pub page_token: Option<String>,
183 #[arg(long)]
185 pub show_deleted: Option<String>,
186}
187
188#[cfg(feature = "clap")]
189impl ListGroupReservationsClapParams {
190 pub async fn execute(
191 self,
192 configuration: &configuration::Configuration,
193 ) -> Result<crate::models::ListReservationsResponse, miette::Error> {
194 list_group_reservations(
195 configuration,
196 self.group_name.as_str(),
197 self.filter.as_deref(),
198 self.order.as_deref(),
199 self.page_size,
200 self.page_token.as_deref(),
201 self.show_deleted.as_deref(),
202 )
203 .await
204 .into_diagnostic()
205 }
206}
207
208#[cfg(feature = "clap")]
210#[derive(Debug, clap::Args)]
211pub struct ListReservationsClapParams {
212 #[arg(long)]
213 pub filter: Option<String>,
214 #[arg(long)]
215 pub order: Option<String>,
216 #[arg(long)]
217 pub page_size: Option<i64>,
218 #[arg(long)]
220 pub page_token: Option<String>,
221 #[arg(long)]
223 pub show_deleted: Option<String>,
224 #[arg(long)]
226 pub x_qcs_account_id: Option<String>,
227 #[arg(long)]
229 pub x_qcs_account_type: Option<crate::models::AccountType>,
230}
231
232#[cfg(feature = "clap")]
233impl ListReservationsClapParams {
234 pub async fn execute(
235 self,
236 configuration: &configuration::Configuration,
237 ) -> Result<crate::models::ListReservationsResponse, miette::Error> {
238 list_reservations(
239 configuration,
240 self.filter.as_deref(),
241 self.order.as_deref(),
242 self.page_size,
243 self.page_token.as_deref(),
244 self.show_deleted.as_deref(),
245 self.x_qcs_account_id.as_deref(),
246 self.x_qcs_account_type,
247 )
248 .await
249 .into_diagnostic()
250 }
251}
252
253#[derive(Debug, Clone, Serialize, Deserialize)]
255#[serde(untagged)]
256pub enum CreateReservationError {
257 Status401(crate::models::Error),
258 Status402(crate::models::Error),
259 Status403(crate::models::Error),
260 Status409(crate::models::Error),
261 Status422(crate::models::Error),
262 UnknownValue(serde_json::Value),
263}
264
265#[derive(Debug, Clone, Serialize, Deserialize)]
267#[serde(untagged)]
268pub enum DeleteReservationError {
269 Status401(crate::models::Error),
270 Status403(crate::models::Error),
271 Status404(crate::models::Error),
272 UnknownValue(serde_json::Value),
273}
274
275#[derive(Debug, Clone, Serialize, Deserialize)]
277#[serde(untagged)]
278pub enum FindAvailableReservationsError {
279 Status401(crate::models::Error),
280 Status422(crate::models::Error),
281 UnknownValue(serde_json::Value),
282}
283
284#[derive(Debug, Clone, Serialize, Deserialize)]
286#[serde(untagged)]
287pub enum GetQuantumProcessorCalendarError {
288 Status403(crate::models::Error),
289 Status404(crate::models::Error),
290 UnknownValue(serde_json::Value),
291}
292
293#[derive(Debug, Clone, Serialize, Deserialize)]
295#[serde(untagged)]
296pub enum GetReservationError {
297 Status401(crate::models::Error),
298 Status403(crate::models::Error),
299 Status404(crate::models::Error),
300 UnknownValue(serde_json::Value),
301}
302
303#[derive(Debug, Clone, Serialize, Deserialize)]
305#[serde(untagged)]
306pub enum ListGroupReservationsError {
307 Status401(crate::models::Error),
308 Status422(crate::models::Error),
309 UnknownValue(serde_json::Value),
310}
311
312#[derive(Debug, Clone, Serialize, Deserialize)]
314#[serde(untagged)]
315pub enum ListReservationsError {
316 Status401(crate::models::Error),
317 Status422(crate::models::Error),
318 UnknownValue(serde_json::Value),
319}
320
321async fn create_reservation_inner(
322 configuration: &configuration::Configuration,
323 backoff: &mut ExponentialBackoff,
324 create_reservation_request: crate::models::CreateReservationRequest,
325 x_qcs_account_id: Option<&str>,
326 x_qcs_account_type: Option<crate::models::AccountType>,
327) -> Result<crate::models::Reservation, Error<CreateReservationError>> {
328 let local_var_configuration = configuration;
329
330 let local_var_client = &local_var_configuration.client;
331
332 let local_var_uri_str = format!(
333 "{}/v1/reservations",
334 local_var_configuration.qcs_config.api_url()
335 );
336 let mut local_var_req_builder =
337 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
338
339 #[cfg(feature = "tracing")]
340 {
341 let local_var_do_tracing = local_var_uri_str
344 .parse::<::url::Url>()
345 .ok()
346 .is_none_or(|url| {
347 configuration
348 .qcs_config
349 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
350 });
351
352 if local_var_do_tracing {
353 ::tracing::debug!(
354 url=%local_var_uri_str,
355 method="POST",
356 "making create_reservation request",
357 );
358 }
359 }
360
361 if let Some(local_var_param_value) = x_qcs_account_id {
362 local_var_req_builder =
363 local_var_req_builder.header("x-qcs-account-id", local_var_param_value.to_string());
364 }
365 if let Some(local_var_param_value) = x_qcs_account_type {
366 local_var_req_builder =
367 local_var_req_builder.header("x-qcs-account-type", local_var_param_value.to_string());
368 }
369
370 {
373 use qcs_api_client_common::configuration::TokenError;
374
375 #[allow(
376 clippy::nonminimal_bool,
377 clippy::eq_op,
378 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
379 )]
380 let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
381
382 let token = local_var_configuration
383 .qcs_config
384 .get_bearer_access_token()
385 .await;
386
387 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
388 #[cfg(feature = "tracing")]
390 tracing::debug!(
391 "No client credentials found, but this call does not require authentication."
392 );
393 } else {
394 local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
395 }
396 }
397
398 local_var_req_builder = local_var_req_builder.json(&create_reservation_request);
399
400 let local_var_req = local_var_req_builder.build()?;
401 let local_var_resp = local_var_client.execute(local_var_req).await?;
402
403 let local_var_status = local_var_resp.status();
404
405 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
406 let local_var_content = local_var_resp.text().await?;
407 serde_json::from_str(&local_var_content).map_err(Error::from)
408 } else {
409 let local_var_retry_delay =
410 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
411 let local_var_content = local_var_resp.text().await?;
412 let local_var_entity: Option<CreateReservationError> =
413 serde_json::from_str(&local_var_content).ok();
414 let local_var_error = ResponseContent {
415 status: local_var_status,
416 content: local_var_content,
417 entity: local_var_entity,
418 retry_delay: local_var_retry_delay,
419 };
420 Err(Error::ResponseError(local_var_error))
421 }
422}
423
424pub async fn create_reservation(
426 configuration: &configuration::Configuration,
427 create_reservation_request: crate::models::CreateReservationRequest,
428 x_qcs_account_id: Option<&str>,
429 x_qcs_account_type: Option<crate::models::AccountType>,
430) -> Result<crate::models::Reservation, Error<CreateReservationError>> {
431 let mut backoff = configuration.backoff.clone();
432 let mut refreshed_credentials = false;
433 let method = reqwest::Method::POST;
434 loop {
435 let result = create_reservation_inner(
436 configuration,
437 &mut backoff,
438 create_reservation_request.clone(),
439 x_qcs_account_id.clone(),
440 x_qcs_account_type.clone(),
441 )
442 .await;
443
444 match result {
445 Ok(result) => return Ok(result),
446 Err(Error::ResponseError(response)) => {
447 if !refreshed_credentials
448 && matches!(
449 response.status,
450 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
451 )
452 {
453 configuration.qcs_config.refresh().await?;
454 refreshed_credentials = true;
455 continue;
456 } else if let Some(duration) = response.retry_delay {
457 tokio::time::sleep(duration).await;
458 continue;
459 }
460
461 return Err(Error::ResponseError(response));
462 }
463 Err(Error::Reqwest(error)) => {
464 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
465 tokio::time::sleep(duration).await;
466 continue;
467 }
468
469 return Err(Error::Reqwest(error));
470 }
471 Err(Error::Io(error)) => {
472 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
473 tokio::time::sleep(duration).await;
474 continue;
475 }
476
477 return Err(Error::Io(error));
478 }
479 Err(error) => return Err(error),
480 }
481 }
482}
483async fn delete_reservation_inner(
484 configuration: &configuration::Configuration,
485 backoff: &mut ExponentialBackoff,
486 reservation_id: i64,
487) -> Result<crate::models::Reservation, Error<DeleteReservationError>> {
488 let local_var_configuration = configuration;
489
490 let local_var_client = &local_var_configuration.client;
491
492 let local_var_uri_str = format!(
493 "{}/v1/reservations/{reservationId}",
494 local_var_configuration.qcs_config.api_url(),
495 reservationId = reservation_id
496 );
497 let mut local_var_req_builder =
498 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
499
500 #[cfg(feature = "tracing")]
501 {
502 let local_var_do_tracing = local_var_uri_str
505 .parse::<::url::Url>()
506 .ok()
507 .is_none_or(|url| {
508 configuration
509 .qcs_config
510 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
511 });
512
513 if local_var_do_tracing {
514 ::tracing::debug!(
515 url=%local_var_uri_str,
516 method="DELETE",
517 "making delete_reservation request",
518 );
519 }
520 }
521
522 {
525 use qcs_api_client_common::configuration::TokenError;
526
527 #[allow(
528 clippy::nonminimal_bool,
529 clippy::eq_op,
530 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
531 )]
532 let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
533
534 let token = local_var_configuration
535 .qcs_config
536 .get_bearer_access_token()
537 .await;
538
539 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
540 #[cfg(feature = "tracing")]
542 tracing::debug!(
543 "No client credentials found, but this call does not require authentication."
544 );
545 } else {
546 local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
547 }
548 }
549
550 let local_var_req = local_var_req_builder.build()?;
551 let local_var_resp = local_var_client.execute(local_var_req).await?;
552
553 let local_var_status = local_var_resp.status();
554
555 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
556 let local_var_content = local_var_resp.text().await?;
557 serde_json::from_str(&local_var_content).map_err(Error::from)
558 } else {
559 let local_var_retry_delay =
560 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
561 let local_var_content = local_var_resp.text().await?;
562 let local_var_entity: Option<DeleteReservationError> =
563 serde_json::from_str(&local_var_content).ok();
564 let local_var_error = ResponseContent {
565 status: local_var_status,
566 content: local_var_content,
567 entity: local_var_entity,
568 retry_delay: local_var_retry_delay,
569 };
570 Err(Error::ResponseError(local_var_error))
571 }
572}
573
574pub async fn delete_reservation(
576 configuration: &configuration::Configuration,
577 reservation_id: i64,
578) -> Result<crate::models::Reservation, Error<DeleteReservationError>> {
579 let mut backoff = configuration.backoff.clone();
580 let mut refreshed_credentials = false;
581 let method = reqwest::Method::DELETE;
582 loop {
583 let result =
584 delete_reservation_inner(configuration, &mut backoff, reservation_id.clone()).await;
585
586 match result {
587 Ok(result) => return Ok(result),
588 Err(Error::ResponseError(response)) => {
589 if !refreshed_credentials
590 && matches!(
591 response.status,
592 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
593 )
594 {
595 configuration.qcs_config.refresh().await?;
596 refreshed_credentials = true;
597 continue;
598 } else if let Some(duration) = response.retry_delay {
599 tokio::time::sleep(duration).await;
600 continue;
601 }
602
603 return Err(Error::ResponseError(response));
604 }
605 Err(Error::Reqwest(error)) => {
606 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
607 tokio::time::sleep(duration).await;
608 continue;
609 }
610
611 return Err(Error::Reqwest(error));
612 }
613 Err(Error::Io(error)) => {
614 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
615 tokio::time::sleep(duration).await;
616 continue;
617 }
618
619 return Err(Error::Io(error));
620 }
621 Err(error) => return Err(error),
622 }
623 }
624}
625async fn find_available_reservations_inner(
626 configuration: &configuration::Configuration,
627 backoff: &mut ExponentialBackoff,
628 quantum_processor_id: &str,
629 start_time_from: String,
630 duration: &str,
631 page_size: Option<i64>,
632 page_token: Option<&str>,
633) -> Result<crate::models::FindAvailableReservationsResponse, Error<FindAvailableReservationsError>>
634{
635 let local_var_configuration = configuration;
636
637 let local_var_client = &local_var_configuration.client;
638
639 let local_var_uri_str = format!(
640 "{}/v1/reservations:findAvailable",
641 local_var_configuration.qcs_config.api_url()
642 );
643 let mut local_var_req_builder =
644 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
645
646 #[cfg(feature = "tracing")]
647 {
648 let local_var_do_tracing = local_var_uri_str
651 .parse::<::url::Url>()
652 .ok()
653 .is_none_or(|url| {
654 configuration
655 .qcs_config
656 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
657 });
658
659 if local_var_do_tracing {
660 ::tracing::debug!(
661 url=%local_var_uri_str,
662 method="GET",
663 "making find_available_reservations request",
664 );
665 }
666 }
667
668 if let Some(ref local_var_str) = page_size {
669 local_var_req_builder =
670 local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
671 }
672 if let Some(ref local_var_str) = page_token {
673 local_var_req_builder =
674 local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
675 }
676 local_var_req_builder =
677 local_var_req_builder.query(&[("quantumProcessorId", &quantum_processor_id.to_string())]);
678 local_var_req_builder =
679 local_var_req_builder.query(&[("startTimeFrom", &start_time_from.to_string())]);
680 local_var_req_builder = local_var_req_builder.query(&[("duration", &duration.to_string())]);
681
682 {
685 use qcs_api_client_common::configuration::TokenError;
686
687 #[allow(
688 clippy::nonminimal_bool,
689 clippy::eq_op,
690 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
691 )]
692 let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
693
694 let token = local_var_configuration
695 .qcs_config
696 .get_bearer_access_token()
697 .await;
698
699 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
700 #[cfg(feature = "tracing")]
702 tracing::debug!(
703 "No client credentials found, but this call does not require authentication."
704 );
705 } else {
706 local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
707 }
708 }
709
710 let local_var_req = local_var_req_builder.build()?;
711 let local_var_resp = local_var_client.execute(local_var_req).await?;
712
713 let local_var_status = local_var_resp.status();
714
715 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
716 let local_var_content = local_var_resp.text().await?;
717 serde_json::from_str(&local_var_content).map_err(Error::from)
718 } else {
719 let local_var_retry_delay =
720 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
721 let local_var_content = local_var_resp.text().await?;
722 let local_var_entity: Option<FindAvailableReservationsError> =
723 serde_json::from_str(&local_var_content).ok();
724 let local_var_error = ResponseContent {
725 status: local_var_status,
726 content: local_var_content,
727 entity: local_var_entity,
728 retry_delay: local_var_retry_delay,
729 };
730 Err(Error::ResponseError(local_var_error))
731 }
732}
733
734pub async fn find_available_reservations(
736 configuration: &configuration::Configuration,
737 quantum_processor_id: &str,
738 start_time_from: String,
739 duration: &str,
740 page_size: Option<i64>,
741 page_token: Option<&str>,
742) -> Result<crate::models::FindAvailableReservationsResponse, Error<FindAvailableReservationsError>>
743{
744 let mut backoff = configuration.backoff.clone();
745 let mut refreshed_credentials = false;
746 let method = reqwest::Method::GET;
747 loop {
748 let result = find_available_reservations_inner(
749 configuration,
750 &mut backoff,
751 quantum_processor_id.clone(),
752 start_time_from.clone(),
753 duration.clone(),
754 page_size.clone(),
755 page_token.clone(),
756 )
757 .await;
758
759 match result {
760 Ok(result) => return Ok(result),
761 Err(Error::ResponseError(response)) => {
762 if !refreshed_credentials
763 && matches!(
764 response.status,
765 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
766 )
767 {
768 configuration.qcs_config.refresh().await?;
769 refreshed_credentials = true;
770 continue;
771 } else if let Some(duration) = response.retry_delay {
772 tokio::time::sleep(duration).await;
773 continue;
774 }
775
776 return Err(Error::ResponseError(response));
777 }
778 Err(Error::Reqwest(error)) => {
779 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
780 tokio::time::sleep(duration).await;
781 continue;
782 }
783
784 return Err(Error::Reqwest(error));
785 }
786 Err(Error::Io(error)) => {
787 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
788 tokio::time::sleep(duration).await;
789 continue;
790 }
791
792 return Err(Error::Io(error));
793 }
794 Err(error) => return Err(error),
795 }
796 }
797}
798async fn get_quantum_processor_calendar_inner(
799 configuration: &configuration::Configuration,
800 backoff: &mut ExponentialBackoff,
801 quantum_processor_id: &str,
802) -> Result<crate::models::QuantumProcessorCalendar, Error<GetQuantumProcessorCalendarError>> {
803 let local_var_configuration = configuration;
804
805 let local_var_client = &local_var_configuration.client;
806
807 let local_var_uri_str = format!(
808 "{}/v1/calendars/{quantumProcessorId}",
809 local_var_configuration.qcs_config.api_url(),
810 quantumProcessorId = crate::apis::urlencode(quantum_processor_id)
811 );
812 let mut local_var_req_builder =
813 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
814
815 #[cfg(feature = "tracing")]
816 {
817 let local_var_do_tracing = local_var_uri_str
820 .parse::<::url::Url>()
821 .ok()
822 .is_none_or(|url| {
823 configuration
824 .qcs_config
825 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
826 });
827
828 if local_var_do_tracing {
829 ::tracing::debug!(
830 url=%local_var_uri_str,
831 method="GET",
832 "making get_quantum_processor_calendar request",
833 );
834 }
835 }
836
837 {
840 use qcs_api_client_common::configuration::TokenError;
841
842 #[allow(
843 clippy::nonminimal_bool,
844 clippy::eq_op,
845 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
846 )]
847 let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
848
849 let token = local_var_configuration
850 .qcs_config
851 .get_bearer_access_token()
852 .await;
853
854 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
855 #[cfg(feature = "tracing")]
857 tracing::debug!(
858 "No client credentials found, but this call does not require authentication."
859 );
860 } else {
861 local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
862 }
863 }
864
865 let local_var_req = local_var_req_builder.build()?;
866 let local_var_resp = local_var_client.execute(local_var_req).await?;
867
868 let local_var_status = local_var_resp.status();
869
870 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
871 let local_var_content = local_var_resp.text().await?;
872 serde_json::from_str(&local_var_content).map_err(Error::from)
873 } else {
874 let local_var_retry_delay =
875 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
876 let local_var_content = local_var_resp.text().await?;
877 let local_var_entity: Option<GetQuantumProcessorCalendarError> =
878 serde_json::from_str(&local_var_content).ok();
879 let local_var_error = ResponseContent {
880 status: local_var_status,
881 content: local_var_content,
882 entity: local_var_entity,
883 retry_delay: local_var_retry_delay,
884 };
885 Err(Error::ResponseError(local_var_error))
886 }
887}
888
889pub async fn get_quantum_processor_calendar(
891 configuration: &configuration::Configuration,
892 quantum_processor_id: &str,
893) -> Result<crate::models::QuantumProcessorCalendar, Error<GetQuantumProcessorCalendarError>> {
894 let mut backoff = configuration.backoff.clone();
895 let mut refreshed_credentials = false;
896 let method = reqwest::Method::GET;
897 loop {
898 let result = get_quantum_processor_calendar_inner(
899 configuration,
900 &mut backoff,
901 quantum_processor_id.clone(),
902 )
903 .await;
904
905 match result {
906 Ok(result) => return Ok(result),
907 Err(Error::ResponseError(response)) => {
908 if !refreshed_credentials
909 && matches!(
910 response.status,
911 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
912 )
913 {
914 configuration.qcs_config.refresh().await?;
915 refreshed_credentials = true;
916 continue;
917 } else if let Some(duration) = response.retry_delay {
918 tokio::time::sleep(duration).await;
919 continue;
920 }
921
922 return Err(Error::ResponseError(response));
923 }
924 Err(Error::Reqwest(error)) => {
925 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
926 tokio::time::sleep(duration).await;
927 continue;
928 }
929
930 return Err(Error::Reqwest(error));
931 }
932 Err(Error::Io(error)) => {
933 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
934 tokio::time::sleep(duration).await;
935 continue;
936 }
937
938 return Err(Error::Io(error));
939 }
940 Err(error) => return Err(error),
941 }
942 }
943}
944async fn get_reservation_inner(
945 configuration: &configuration::Configuration,
946 backoff: &mut ExponentialBackoff,
947 reservation_id: i64,
948) -> Result<crate::models::Reservation, Error<GetReservationError>> {
949 let local_var_configuration = configuration;
950
951 let local_var_client = &local_var_configuration.client;
952
953 let local_var_uri_str = format!(
954 "{}/v1/reservations/{reservationId}",
955 local_var_configuration.qcs_config.api_url(),
956 reservationId = reservation_id
957 );
958 let mut local_var_req_builder =
959 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
960
961 #[cfg(feature = "tracing")]
962 {
963 let local_var_do_tracing = local_var_uri_str
966 .parse::<::url::Url>()
967 .ok()
968 .is_none_or(|url| {
969 configuration
970 .qcs_config
971 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
972 });
973
974 if local_var_do_tracing {
975 ::tracing::debug!(
976 url=%local_var_uri_str,
977 method="GET",
978 "making get_reservation request",
979 );
980 }
981 }
982
983 {
986 use qcs_api_client_common::configuration::TokenError;
987
988 #[allow(
989 clippy::nonminimal_bool,
990 clippy::eq_op,
991 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
992 )]
993 let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
994
995 let token = local_var_configuration
996 .qcs_config
997 .get_bearer_access_token()
998 .await;
999
1000 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1001 #[cfg(feature = "tracing")]
1003 tracing::debug!(
1004 "No client credentials found, but this call does not require authentication."
1005 );
1006 } else {
1007 local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
1008 }
1009 }
1010
1011 let local_var_req = local_var_req_builder.build()?;
1012 let local_var_resp = local_var_client.execute(local_var_req).await?;
1013
1014 let local_var_status = local_var_resp.status();
1015
1016 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1017 let local_var_content = local_var_resp.text().await?;
1018 serde_json::from_str(&local_var_content).map_err(Error::from)
1019 } else {
1020 let local_var_retry_delay =
1021 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1022 let local_var_content = local_var_resp.text().await?;
1023 let local_var_entity: Option<GetReservationError> =
1024 serde_json::from_str(&local_var_content).ok();
1025 let local_var_error = ResponseContent {
1026 status: local_var_status,
1027 content: local_var_content,
1028 entity: local_var_entity,
1029 retry_delay: local_var_retry_delay,
1030 };
1031 Err(Error::ResponseError(local_var_error))
1032 }
1033}
1034
1035pub async fn get_reservation(
1037 configuration: &configuration::Configuration,
1038 reservation_id: i64,
1039) -> Result<crate::models::Reservation, Error<GetReservationError>> {
1040 let mut backoff = configuration.backoff.clone();
1041 let mut refreshed_credentials = false;
1042 let method = reqwest::Method::GET;
1043 loop {
1044 let result =
1045 get_reservation_inner(configuration, &mut backoff, reservation_id.clone()).await;
1046
1047 match result {
1048 Ok(result) => return Ok(result),
1049 Err(Error::ResponseError(response)) => {
1050 if !refreshed_credentials
1051 && matches!(
1052 response.status,
1053 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1054 )
1055 {
1056 configuration.qcs_config.refresh().await?;
1057 refreshed_credentials = true;
1058 continue;
1059 } else if let Some(duration) = response.retry_delay {
1060 tokio::time::sleep(duration).await;
1061 continue;
1062 }
1063
1064 return Err(Error::ResponseError(response));
1065 }
1066 Err(Error::Reqwest(error)) => {
1067 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1068 tokio::time::sleep(duration).await;
1069 continue;
1070 }
1071
1072 return Err(Error::Reqwest(error));
1073 }
1074 Err(Error::Io(error)) => {
1075 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1076 tokio::time::sleep(duration).await;
1077 continue;
1078 }
1079
1080 return Err(Error::Io(error));
1081 }
1082 Err(error) => return Err(error),
1083 }
1084 }
1085}
1086async fn list_group_reservations_inner(
1087 configuration: &configuration::Configuration,
1088 backoff: &mut ExponentialBackoff,
1089 group_name: &str,
1090 filter: Option<&str>,
1091 order: Option<&str>,
1092 page_size: Option<i64>,
1093 page_token: Option<&str>,
1094 show_deleted: Option<&str>,
1095) -> Result<crate::models::ListReservationsResponse, Error<ListGroupReservationsError>> {
1096 let local_var_configuration = configuration;
1097
1098 let local_var_client = &local_var_configuration.client;
1099
1100 let local_var_uri_str = format!(
1101 "{}/v1/groups/{groupName}/reservations",
1102 local_var_configuration.qcs_config.api_url(),
1103 groupName = crate::apis::urlencode(group_name)
1104 );
1105 let mut local_var_req_builder =
1106 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1107
1108 #[cfg(feature = "tracing")]
1109 {
1110 let local_var_do_tracing = local_var_uri_str
1113 .parse::<::url::Url>()
1114 .ok()
1115 .is_none_or(|url| {
1116 configuration
1117 .qcs_config
1118 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1119 });
1120
1121 if local_var_do_tracing {
1122 ::tracing::debug!(
1123 url=%local_var_uri_str,
1124 method="GET",
1125 "making list_group_reservations request",
1126 );
1127 }
1128 }
1129
1130 if let Some(ref local_var_str) = filter {
1131 local_var_req_builder =
1132 local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
1133 }
1134 if let Some(ref local_var_str) = order {
1135 local_var_req_builder =
1136 local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
1137 }
1138 if let Some(ref local_var_str) = page_size {
1139 local_var_req_builder =
1140 local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
1141 }
1142 if let Some(ref local_var_str) = page_token {
1143 local_var_req_builder =
1144 local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
1145 }
1146 if let Some(ref local_var_str) = show_deleted {
1147 local_var_req_builder =
1148 local_var_req_builder.query(&[("showDeleted", &local_var_str.to_string())]);
1149 }
1150
1151 {
1154 use qcs_api_client_common::configuration::TokenError;
1155
1156 #[allow(
1157 clippy::nonminimal_bool,
1158 clippy::eq_op,
1159 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1160 )]
1161 let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1162
1163 let token = local_var_configuration
1164 .qcs_config
1165 .get_bearer_access_token()
1166 .await;
1167
1168 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1169 #[cfg(feature = "tracing")]
1171 tracing::debug!(
1172 "No client credentials found, but this call does not require authentication."
1173 );
1174 } else {
1175 local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
1176 }
1177 }
1178
1179 let local_var_req = local_var_req_builder.build()?;
1180 let local_var_resp = local_var_client.execute(local_var_req).await?;
1181
1182 let local_var_status = local_var_resp.status();
1183
1184 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1185 let local_var_content = local_var_resp.text().await?;
1186 serde_json::from_str(&local_var_content).map_err(Error::from)
1187 } else {
1188 let local_var_retry_delay =
1189 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1190 let local_var_content = local_var_resp.text().await?;
1191 let local_var_entity: Option<ListGroupReservationsError> =
1192 serde_json::from_str(&local_var_content).ok();
1193 let local_var_error = ResponseContent {
1194 status: local_var_status,
1195 content: local_var_content,
1196 entity: local_var_entity,
1197 retry_delay: local_var_retry_delay,
1198 };
1199 Err(Error::ResponseError(local_var_error))
1200 }
1201}
1202
1203pub async fn list_group_reservations(
1205 configuration: &configuration::Configuration,
1206 group_name: &str,
1207 filter: Option<&str>,
1208 order: Option<&str>,
1209 page_size: Option<i64>,
1210 page_token: Option<&str>,
1211 show_deleted: Option<&str>,
1212) -> Result<crate::models::ListReservationsResponse, Error<ListGroupReservationsError>> {
1213 let mut backoff = configuration.backoff.clone();
1214 let mut refreshed_credentials = false;
1215 let method = reqwest::Method::GET;
1216 loop {
1217 let result = list_group_reservations_inner(
1218 configuration,
1219 &mut backoff,
1220 group_name.clone(),
1221 filter.clone(),
1222 order.clone(),
1223 page_size.clone(),
1224 page_token.clone(),
1225 show_deleted.clone(),
1226 )
1227 .await;
1228
1229 match result {
1230 Ok(result) => return Ok(result),
1231 Err(Error::ResponseError(response)) => {
1232 if !refreshed_credentials
1233 && matches!(
1234 response.status,
1235 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1236 )
1237 {
1238 configuration.qcs_config.refresh().await?;
1239 refreshed_credentials = true;
1240 continue;
1241 } else if let Some(duration) = response.retry_delay {
1242 tokio::time::sleep(duration).await;
1243 continue;
1244 }
1245
1246 return Err(Error::ResponseError(response));
1247 }
1248 Err(Error::Reqwest(error)) => {
1249 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1250 tokio::time::sleep(duration).await;
1251 continue;
1252 }
1253
1254 return Err(Error::Reqwest(error));
1255 }
1256 Err(Error::Io(error)) => {
1257 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1258 tokio::time::sleep(duration).await;
1259 continue;
1260 }
1261
1262 return Err(Error::Io(error));
1263 }
1264 Err(error) => return Err(error),
1265 }
1266 }
1267}
1268async fn list_reservations_inner(
1269 configuration: &configuration::Configuration,
1270 backoff: &mut ExponentialBackoff,
1271 filter: Option<&str>,
1272 order: Option<&str>,
1273 page_size: Option<i64>,
1274 page_token: Option<&str>,
1275 show_deleted: Option<&str>,
1276 x_qcs_account_id: Option<&str>,
1277 x_qcs_account_type: Option<crate::models::AccountType>,
1278) -> Result<crate::models::ListReservationsResponse, Error<ListReservationsError>> {
1279 let local_var_configuration = configuration;
1280
1281 let local_var_client = &local_var_configuration.client;
1282
1283 let local_var_uri_str = format!(
1284 "{}/v1/reservations",
1285 local_var_configuration.qcs_config.api_url()
1286 );
1287 let mut local_var_req_builder =
1288 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1289
1290 #[cfg(feature = "tracing")]
1291 {
1292 let local_var_do_tracing = local_var_uri_str
1295 .parse::<::url::Url>()
1296 .ok()
1297 .is_none_or(|url| {
1298 configuration
1299 .qcs_config
1300 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
1301 });
1302
1303 if local_var_do_tracing {
1304 ::tracing::debug!(
1305 url=%local_var_uri_str,
1306 method="GET",
1307 "making list_reservations request",
1308 );
1309 }
1310 }
1311
1312 if let Some(ref local_var_str) = filter {
1313 local_var_req_builder =
1314 local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
1315 }
1316 if let Some(ref local_var_str) = order {
1317 local_var_req_builder =
1318 local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
1319 }
1320 if let Some(ref local_var_str) = page_size {
1321 local_var_req_builder =
1322 local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
1323 }
1324 if let Some(ref local_var_str) = page_token {
1325 local_var_req_builder =
1326 local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
1327 }
1328 if let Some(ref local_var_str) = show_deleted {
1329 local_var_req_builder =
1330 local_var_req_builder.query(&[("showDeleted", &local_var_str.to_string())]);
1331 }
1332 if let Some(local_var_param_value) = x_qcs_account_id {
1333 local_var_req_builder =
1334 local_var_req_builder.header("x-qcs-account-id", local_var_param_value.to_string());
1335 }
1336 if let Some(local_var_param_value) = x_qcs_account_type {
1337 local_var_req_builder =
1338 local_var_req_builder.header("x-qcs-account-type", local_var_param_value.to_string());
1339 }
1340
1341 {
1344 use qcs_api_client_common::configuration::TokenError;
1345
1346 #[allow(
1347 clippy::nonminimal_bool,
1348 clippy::eq_op,
1349 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
1350 )]
1351 let is_jwt_bearer_optional: bool = false || "JWTBearer" == "JWTBearerOptional";
1352
1353 let token = local_var_configuration
1354 .qcs_config
1355 .get_bearer_access_token()
1356 .await;
1357
1358 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
1359 #[cfg(feature = "tracing")]
1361 tracing::debug!(
1362 "No client credentials found, but this call does not require authentication."
1363 );
1364 } else {
1365 local_var_req_builder = local_var_req_builder.bearer_auth(token?.secret());
1366 }
1367 }
1368
1369 let local_var_req = local_var_req_builder.build()?;
1370 let local_var_resp = local_var_client.execute(local_var_req).await?;
1371
1372 let local_var_status = local_var_resp.status();
1373
1374 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1375 let local_var_content = local_var_resp.text().await?;
1376 serde_json::from_str(&local_var_content).map_err(Error::from)
1377 } else {
1378 let local_var_retry_delay =
1379 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
1380 let local_var_content = local_var_resp.text().await?;
1381 let local_var_entity: Option<ListReservationsError> =
1382 serde_json::from_str(&local_var_content).ok();
1383 let local_var_error = ResponseContent {
1384 status: local_var_status,
1385 content: local_var_content,
1386 entity: local_var_entity,
1387 retry_delay: local_var_retry_delay,
1388 };
1389 Err(Error::ResponseError(local_var_error))
1390 }
1391}
1392
1393pub async fn list_reservations(
1395 configuration: &configuration::Configuration,
1396 filter: Option<&str>,
1397 order: Option<&str>,
1398 page_size: Option<i64>,
1399 page_token: Option<&str>,
1400 show_deleted: Option<&str>,
1401 x_qcs_account_id: Option<&str>,
1402 x_qcs_account_type: Option<crate::models::AccountType>,
1403) -> Result<crate::models::ListReservationsResponse, Error<ListReservationsError>> {
1404 let mut backoff = configuration.backoff.clone();
1405 let mut refreshed_credentials = false;
1406 let method = reqwest::Method::GET;
1407 loop {
1408 let result = list_reservations_inner(
1409 configuration,
1410 &mut backoff,
1411 filter.clone(),
1412 order.clone(),
1413 page_size.clone(),
1414 page_token.clone(),
1415 show_deleted.clone(),
1416 x_qcs_account_id.clone(),
1417 x_qcs_account_type.clone(),
1418 )
1419 .await;
1420
1421 match result {
1422 Ok(result) => return Ok(result),
1423 Err(Error::ResponseError(response)) => {
1424 if !refreshed_credentials
1425 && matches!(
1426 response.status,
1427 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
1428 )
1429 {
1430 configuration.qcs_config.refresh().await?;
1431 refreshed_credentials = true;
1432 continue;
1433 } else if let Some(duration) = response.retry_delay {
1434 tokio::time::sleep(duration).await;
1435 continue;
1436 }
1437
1438 return Err(Error::ResponseError(response));
1439 }
1440 Err(Error::Reqwest(error)) => {
1441 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
1442 tokio::time::sleep(duration).await;
1443 continue;
1444 }
1445
1446 return Err(Error::Reqwest(error));
1447 }
1448 Err(Error::Io(error)) => {
1449 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
1450 tokio::time::sleep(duration).await;
1451 continue;
1452 }
1453
1454 return Err(Error::Io(error));
1455 }
1456 Err(error) => return Err(error),
1457 }
1458 }
1459}