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