1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ConfirmOnHoldOfferError {
22 Status400(models::Problem),
23 Status401(models::Problem),
24 Status403(models::Problem),
25 Status404(models::Problem),
26 Status406(models::Problem),
27 Status409(models::Problem),
28 Status415(models::Problem),
29 Status500(models::Problem),
30 Status501(models::Problem),
31 Status503(models::Problem),
32 DefaultResponse(models::Problem),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum CreateOnHoldOfferError {
40 Status400(models::Problem),
41 Status401(models::Problem),
42 Status403(models::Problem),
43 Status404(models::Problem),
44 Status406(models::Problem),
45 Status415(models::Problem),
46 Status500(models::Problem),
47 Status501(models::Problem),
48 Status503(models::Problem),
49 DefaultResponse(models::Problem),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum DeleteOnHoldOfferError {
57 Status400(models::Problem),
58 Status401(models::Problem),
59 Status403(models::Problem),
60 Status404(models::Problem),
61 Status406(models::Problem),
62 Status409(models::Problem),
63 Status415(models::Problem),
64 Status500(models::Problem),
65 Status501(models::Problem),
66 Status503(models::Problem),
67 DefaultResponse(models::Problem),
68 UnknownValue(serde_json::Value),
69}
70
71
72pub async fn confirm_on_hold_offer(configuration: &configuration::Configuration, booking_id: &str, on_hold_offer_id: &str, body: serde_json::Value, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>) -> Result<models::OnHoldOfferResponse, Error<ConfirmOnHoldOfferError>> {
73 let p_path_booking_id = booking_id;
75 let p_path_on_hold_offer_id = on_hold_offer_id;
76 let p_body_body = body;
77 let p_header_requestor = requestor;
78 let p_header_accept_language = accept_language;
79 let p_header_traceparent = traceparent;
80 let p_header_tracestate = tracestate;
81 let p_header_idempotency_key = idempotency_key;
82
83 let uri_str = format!("{}/bookings/{bookingId}/on-hold-offer/{onHoldOfferId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), onHoldOfferId=crate::apis::urlencode(p_path_on_hold_offer_id));
84 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
85
86 if let Some(ref user_agent) = configuration.user_agent {
87 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88 }
89 if let Some(param_value) = p_header_requestor {
90 req_builder = req_builder.header("Requestor", param_value.to_string());
91 }
92 if let Some(param_value) = p_header_accept_language {
93 req_builder = req_builder.header("Accept-Language", param_value.to_string());
94 }
95 if let Some(param_value) = p_header_traceparent {
96 req_builder = req_builder.header("traceparent", param_value.to_string());
97 }
98 if let Some(param_value) = p_header_tracestate {
99 req_builder = req_builder.header("tracestate", param_value.to_string());
100 }
101 if let Some(param_value) = p_header_idempotency_key {
102 req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
103 }
104 if let Some(ref token) = configuration.oauth_access_token {
105 req_builder = req_builder.bearer_auth(token.to_owned());
106 };
107 req_builder = req_builder.json(&p_body_body);
108
109 let req = req_builder.build()?;
110 let resp = configuration.client.execute(req).await?;
111
112 let status = resp.status();
113 let content_type = resp
114 .headers()
115 .get("content-type")
116 .and_then(|v| v.to_str().ok())
117 .unwrap_or("application/octet-stream");
118 let content_type = super::ContentType::from(content_type);
119
120 if !status.is_client_error() && !status.is_server_error() {
121 let content = resp.text().await?;
122 match content_type {
123 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
124 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OnHoldOfferResponse`"))),
125 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::OnHoldOfferResponse`")))),
126 }
127 } else {
128 let content = resp.text().await?;
129 let entity: Option<ConfirmOnHoldOfferError> = serde_json::from_str(&content).ok();
130 Err(Error::ResponseError(ResponseContent { status, content, entity }))
131 }
132}
133
134pub async fn create_on_hold_offer(configuration: &configuration::Configuration, booking_id: &str, on_hold_offer_request: models::OnHoldOfferRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>) -> Result<models::OnHoldOfferResponse, Error<CreateOnHoldOfferError>> {
136 let p_path_booking_id = booking_id;
138 let p_body_on_hold_offer_request = on_hold_offer_request;
139 let p_header_requestor = requestor;
140 let p_header_accept_language = accept_language;
141 let p_header_traceparent = traceparent;
142 let p_header_tracestate = tracestate;
143 let p_header_idempotency_key = idempotency_key;
144
145 let uri_str = format!("{}/bookings/{bookingId}/on-hold-offer", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id));
146 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
147
148 if let Some(ref user_agent) = configuration.user_agent {
149 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
150 }
151 if let Some(param_value) = p_header_requestor {
152 req_builder = req_builder.header("Requestor", param_value.to_string());
153 }
154 if let Some(param_value) = p_header_accept_language {
155 req_builder = req_builder.header("Accept-Language", param_value.to_string());
156 }
157 if let Some(param_value) = p_header_traceparent {
158 req_builder = req_builder.header("traceparent", param_value.to_string());
159 }
160 if let Some(param_value) = p_header_tracestate {
161 req_builder = req_builder.header("tracestate", param_value.to_string());
162 }
163 if let Some(param_value) = p_header_idempotency_key {
164 req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
165 }
166 if let Some(ref token) = configuration.oauth_access_token {
167 req_builder = req_builder.bearer_auth(token.to_owned());
168 };
169 req_builder = req_builder.json(&p_body_on_hold_offer_request);
170
171 let req = req_builder.build()?;
172 let resp = configuration.client.execute(req).await?;
173
174 let status = resp.status();
175 let content_type = resp
176 .headers()
177 .get("content-type")
178 .and_then(|v| v.to_str().ok())
179 .unwrap_or("application/octet-stream");
180 let content_type = super::ContentType::from(content_type);
181
182 if !status.is_client_error() && !status.is_server_error() {
183 let content = resp.text().await?;
184 match content_type {
185 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
186 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OnHoldOfferResponse`"))),
187 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::OnHoldOfferResponse`")))),
188 }
189 } else {
190 let content = resp.text().await?;
191 let entity: Option<CreateOnHoldOfferError> = serde_json::from_str(&content).ok();
192 Err(Error::ResponseError(ResponseContent { status, content, entity }))
193 }
194}
195
196pub async fn delete_on_hold_offer(configuration: &configuration::Configuration, booking_id: &str, on_hold_offer_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<(), Error<DeleteOnHoldOfferError>> {
197 let p_path_booking_id = booking_id;
199 let p_path_on_hold_offer_id = on_hold_offer_id;
200 let p_header_requestor = requestor;
201 let p_header_accept_language = accept_language;
202 let p_header_traceparent = traceparent;
203 let p_header_tracestate = tracestate;
204
205 let uri_str = format!("{}/bookings/{bookingId}/on-hold-offer/{onHoldOfferId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), onHoldOfferId=crate::apis::urlencode(p_path_on_hold_offer_id));
206 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
207
208 if let Some(ref user_agent) = configuration.user_agent {
209 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
210 }
211 if let Some(param_value) = p_header_requestor {
212 req_builder = req_builder.header("Requestor", param_value.to_string());
213 }
214 if let Some(param_value) = p_header_accept_language {
215 req_builder = req_builder.header("Accept-Language", param_value.to_string());
216 }
217 if let Some(param_value) = p_header_traceparent {
218 req_builder = req_builder.header("traceparent", param_value.to_string());
219 }
220 if let Some(param_value) = p_header_tracestate {
221 req_builder = req_builder.header("tracestate", param_value.to_string());
222 }
223 if let Some(ref token) = configuration.oauth_access_token {
224 req_builder = req_builder.bearer_auth(token.to_owned());
225 };
226
227 let req = req_builder.build()?;
228 let resp = configuration.client.execute(req).await?;
229
230 let status = resp.status();
231
232 if !status.is_client_error() && !status.is_server_error() {
233 Ok(())
234 } else {
235 let content = resp.text().await?;
236 let entity: Option<DeleteOnHoldOfferError> = serde_json::from_str(&content).ok();
237 Err(Error::ResponseError(ResponseContent { status, content, entity }))
238 }
239}
240