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