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 GetBookingConfigError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetBookingScheduleError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PostBookingReserveError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostBookingReserveConfirmationError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PutBookingReserveByIdError {
50 UnknownValue(serde_json::Value),
51}
52
53
54pub async fn get_booking_config(configuration: &configuration::Configuration, id: &str) -> Result<models::TenantConfig, Error<GetBookingConfigError>> {
56 let p_id = id;
58
59 let uri_str = format!("{}/booking/config/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
60 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
61
62 if let Some(ref user_agent) = configuration.user_agent {
63 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64 }
65
66 let req = req_builder.build()?;
67 let resp = configuration.client.execute(req).await?;
68
69 let status = resp.status();
70 let content_type = resp
71 .headers()
72 .get("content-type")
73 .and_then(|v| v.to_str().ok())
74 .unwrap_or("application/octet-stream");
75 let content_type = super::ContentType::from(content_type);
76
77 if !status.is_client_error() && !status.is_server_error() {
78 let content = resp.text().await?;
79 match content_type {
80 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
81 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TenantConfig`"))),
82 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::TenantConfig`")))),
83 }
84 } else {
85 let content = resp.text().await?;
86 let entity: Option<GetBookingConfigError> = serde_json::from_str(&content).ok();
87 Err(Error::ResponseError(ResponseContent { status, content, entity }))
88 }
89}
90
91pub async fn get_booking_schedule(configuration: &configuration::Configuration, tid: &str, sid: &str, wid: &str, date: String) -> Result<models::Availabilities, Error<GetBookingScheduleError>> {
93 let p_tid = tid;
95 let p_sid = sid;
96 let p_wid = wid;
97 let p_date = date;
98
99 let uri_str = format!("{}/booking/schedule/{tid}/{sid}/{wid}/{date}", configuration.base_path, tid=crate::apis::urlencode(p_tid), sid=crate::apis::urlencode(p_sid), wid=crate::apis::urlencode(p_wid), date=p_date);
100 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
101
102 if let Some(ref user_agent) = configuration.user_agent {
103 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
104 }
105
106 let req = req_builder.build()?;
107 let resp = configuration.client.execute(req).await?;
108
109 let status = resp.status();
110 let content_type = resp
111 .headers()
112 .get("content-type")
113 .and_then(|v| v.to_str().ok())
114 .unwrap_or("application/octet-stream");
115 let content_type = super::ContentType::from(content_type);
116
117 if !status.is_client_error() && !status.is_server_error() {
118 let content = resp.text().await?;
119 match content_type {
120 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
121 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Availabilities`"))),
122 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::Availabilities`")))),
123 }
124 } else {
125 let content = resp.text().await?;
126 let entity: Option<GetBookingScheduleError> = serde_json::from_str(&content).ok();
127 Err(Error::ResponseError(ResponseContent { status, content, entity }))
128 }
129}
130
131pub async fn post_booking_reserve(configuration: &configuration::Configuration, reservation_request: models::ReservationRequest) -> Result<models::ReservationResponse, Error<PostBookingReserveError>> {
133 let p_reservation_request = reservation_request;
135
136 let uri_str = format!("{}/booking/reserve", configuration.base_path);
137 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
138
139 if let Some(ref user_agent) = configuration.user_agent {
140 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
141 }
142 req_builder = req_builder.json(&p_reservation_request);
143
144 let req = req_builder.build()?;
145 let resp = configuration.client.execute(req).await?;
146
147 let status = resp.status();
148 let content_type = resp
149 .headers()
150 .get("content-type")
151 .and_then(|v| v.to_str().ok())
152 .unwrap_or("application/octet-stream");
153 let content_type = super::ContentType::from(content_type);
154
155 if !status.is_client_error() && !status.is_server_error() {
156 let content = resp.text().await?;
157 match content_type {
158 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReservationResponse`"))),
160 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::ReservationResponse`")))),
161 }
162 } else {
163 let content = resp.text().await?;
164 let entity: Option<PostBookingReserveError> = serde_json::from_str(&content).ok();
165 Err(Error::ResponseError(ResponseContent { status, content, entity }))
166 }
167}
168
169pub async fn post_booking_reserve_confirmation(configuration: &configuration::Configuration, rid: &str, confirmation_request: models::ConfirmationRequest) -> Result<models::ConfirmationResponse, Error<PostBookingReserveConfirmationError>> {
171 let p_rid = rid;
173 let p_confirmation_request = confirmation_request;
174
175 let uri_str = format!("{}/booking/reserve/{rid}/confirmation", configuration.base_path, rid=crate::apis::urlencode(p_rid));
176 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
177
178 if let Some(ref user_agent) = configuration.user_agent {
179 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
180 }
181 req_builder = req_builder.json(&p_confirmation_request);
182
183 let req = req_builder.build()?;
184 let resp = configuration.client.execute(req).await?;
185
186 let status = resp.status();
187 let content_type = resp
188 .headers()
189 .get("content-type")
190 .and_then(|v| v.to_str().ok())
191 .unwrap_or("application/octet-stream");
192 let content_type = super::ContentType::from(content_type);
193
194 if !status.is_client_error() && !status.is_server_error() {
195 let content = resp.text().await?;
196 match content_type {
197 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
198 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfirmationResponse`"))),
199 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::ConfirmationResponse`")))),
200 }
201 } else {
202 let content = resp.text().await?;
203 let entity: Option<PostBookingReserveConfirmationError> = serde_json::from_str(&content).ok();
204 Err(Error::ResponseError(ResponseContent { status, content, entity }))
205 }
206}
207
208pub async fn put_booking_reserve_by_id(configuration: &configuration::Configuration, rid: &str, reservation_request: models::ReservationRequest) -> Result<models::ReservationResponse, Error<PutBookingReserveByIdError>> {
210 let p_rid = rid;
212 let p_reservation_request = reservation_request;
213
214 let uri_str = format!("{}/booking/reserve/{rid}", configuration.base_path, rid=crate::apis::urlencode(p_rid));
215 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
216
217 if let Some(ref user_agent) = configuration.user_agent {
218 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
219 }
220 req_builder = req_builder.json(&p_reservation_request);
221
222 let req = req_builder.build()?;
223 let resp = configuration.client.execute(req).await?;
224
225 let status = resp.status();
226 let content_type = resp
227 .headers()
228 .get("content-type")
229 .and_then(|v| v.to_str().ok())
230 .unwrap_or("application/octet-stream");
231 let content_type = super::ContentType::from(content_type);
232
233 if !status.is_client_error() && !status.is_server_error() {
234 let content = resp.text().await?;
235 match content_type {
236 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
237 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReservationResponse`"))),
238 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::ReservationResponse`")))),
239 }
240 } else {
241 let content = resp.text().await?;
242 let entity: Option<PutBookingReserveByIdError> = serde_json::from_str(&content).ok();
243 Err(Error::ResponseError(ResponseContent { status, content, entity }))
244 }
245}
246