1#![allow(deprecated)]
2use super::{configuration, ContentType, Error};
13use crate::{apis::ResponseContent, models};
14use serde::{de::Error as _, Deserialize, Serialize};
15use timvw_rust_runtime;
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum EvaluationRulesCreateError {
21 Status400(serde_json::Value),
22 Status401(serde_json::Value),
23 Status403(serde_json::Value),
24 Status404(serde_json::Value),
25 Status405(serde_json::Value),
26 Status409(models::PublicApiError),
27 Status429(models::PublicApiError),
28 Status500(models::PublicApiError),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum EvaluationRulesDeleteError {
36 Status400(serde_json::Value),
37 Status401(serde_json::Value),
38 Status403(serde_json::Value),
39 Status404(serde_json::Value),
40 Status405(serde_json::Value),
41 Status429(models::PublicApiError),
42 Status500(models::PublicApiError),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum EvaluationRulesGetError {
50 Status400(serde_json::Value),
51 Status401(serde_json::Value),
52 Status403(serde_json::Value),
53 Status404(serde_json::Value),
54 Status405(serde_json::Value),
55 Status429(models::PublicApiError),
56 Status500(models::PublicApiError),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum EvaluationRulesListError {
64 Status400(serde_json::Value),
65 Status401(serde_json::Value),
66 Status403(serde_json::Value),
67 Status404(serde_json::Value),
68 Status405(serde_json::Value),
69 Status429(models::PublicApiError),
70 Status500(models::PublicApiError),
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum EvaluationRulesUpdateError {
78 Status400(serde_json::Value),
79 Status401(serde_json::Value),
80 Status403(serde_json::Value),
81 Status404(serde_json::Value),
82 Status405(serde_json::Value),
83 Status409(models::PublicApiError),
84 Status429(models::PublicApiError),
85 Status500(models::PublicApiError),
86 UnknownValue(serde_json::Value),
87}
88
89#[bon::builder]
91pub async fn evaluation_rules_create(
92 configuration: &configuration::Configuration,
93 create_evaluation_rule_request: &models::CreateEvaluationRuleRequest,
94 options: Option<&timvw_rust_runtime::RequestOptions>,
95) -> Result<models::EvaluationRule, Error<EvaluationRulesCreateError>> {
96 let p_body_create_evaluation_rule_request = create_evaluation_rule_request;
98
99 let uri_str = format!("{}/api/public/v2/evaluation-rules", configuration.base_path);
100 let mut req_builder = configuration
101 .client
102 .request(timvw_rust_runtime::Method::POST, &uri_str);
103
104 if let Some(ref user_agent) = configuration.user_agent {
105 req_builder =
106 req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
107 }
108 if let Some(ref auth_conf) = configuration.basic_auth {
109 req_builder = req_builder.basic_auth(
110 &auth_conf.0,
111 auth_conf
112 .1
113 .as_ref()
114 .map(timvw_rust_runtime::ExposeSecret::expose_secret),
115 );
116 };
117 req_builder = req_builder.json(p_body_create_evaluation_rule_request);
118
119 if let Some(options) = options {
121 req_builder = req_builder.base(&configuration.base_path).options(options);
122 }
123 let req = req_builder.build()?;
124 let resp = configuration.client.execute(req).await?;
125
126 let status = resp.status();
127 let content_type = resp
128 .headers()
129 .get("content-type")
130 .and_then(|v| v.to_str().ok())
131 .unwrap_or("application/octet-stream");
132 let content_type = super::ContentType::from(content_type);
133
134 if !status.is_client_error() && !status.is_server_error() {
135 let content = resp.text().await?;
136 match content_type {
137 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
138 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EvaluationRule`"))),
139 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EvaluationRule`")))),
140 }
141 } else {
142 let headers = resp.headers().clone();
143 let content = resp.text().await?;
144 let entity: Option<EvaluationRulesCreateError> = match status.as_u16() {
145 400 => serde_json::from_str(&content)
146 .ok()
147 .map(EvaluationRulesCreateError::Status400),
148 401 => serde_json::from_str(&content)
149 .ok()
150 .map(EvaluationRulesCreateError::Status401),
151 403 => serde_json::from_str(&content)
152 .ok()
153 .map(EvaluationRulesCreateError::Status403),
154 404 => serde_json::from_str(&content)
155 .ok()
156 .map(EvaluationRulesCreateError::Status404),
157 405 => serde_json::from_str(&content)
158 .ok()
159 .map(EvaluationRulesCreateError::Status405),
160 409 => serde_json::from_str(&content)
161 .ok()
162 .map(EvaluationRulesCreateError::Status409),
163 429 => serde_json::from_str(&content)
164 .ok()
165 .map(EvaluationRulesCreateError::Status429),
166 500 => serde_json::from_str(&content)
167 .ok()
168 .map(EvaluationRulesCreateError::Status500),
169 _ => None,
170 }
171 .or_else(|| {
172 serde_json::from_str(&content)
173 .ok()
174 .map(EvaluationRulesCreateError::UnknownValue)
175 });
176 Err(Error::ResponseError(Box::new(ResponseContent {
177 status,
178 content,
179 entity,
180 headers,
181 })))
182 }
183}
184
185#[bon::builder]
187pub async fn evaluation_rules_delete(
188 configuration: &configuration::Configuration,
189 evaluation_rule_id: &str,
190 options: Option<&timvw_rust_runtime::RequestOptions>,
191) -> Result<models::DeletedEvaluationRule, Error<EvaluationRulesDeleteError>> {
192 let p_path_evaluation_rule_id = evaluation_rule_id;
194
195 let uri_str = format!(
196 "{}/api/public/v2/evaluation-rules/{evaluationRuleId}",
197 configuration.base_path,
198 evaluationRuleId = crate::apis::urlencode(p_path_evaluation_rule_id)
199 );
200 let mut req_builder = configuration
201 .client
202 .request(timvw_rust_runtime::Method::DELETE, &uri_str);
203
204 if let Some(ref user_agent) = configuration.user_agent {
205 req_builder =
206 req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
207 }
208 if let Some(ref auth_conf) = configuration.basic_auth {
209 req_builder = req_builder.basic_auth(
210 &auth_conf.0,
211 auth_conf
212 .1
213 .as_ref()
214 .map(timvw_rust_runtime::ExposeSecret::expose_secret),
215 );
216 };
217
218 if let Some(options) = options {
220 req_builder = req_builder.base(&configuration.base_path).options(options);
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 => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeletedEvaluationRule`"))),
238 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeletedEvaluationRule`")))),
239 }
240 } else {
241 let headers = resp.headers().clone();
242 let content = resp.text().await?;
243 let entity: Option<EvaluationRulesDeleteError> = match status.as_u16() {
244 400 => serde_json::from_str(&content)
245 .ok()
246 .map(EvaluationRulesDeleteError::Status400),
247 401 => serde_json::from_str(&content)
248 .ok()
249 .map(EvaluationRulesDeleteError::Status401),
250 403 => serde_json::from_str(&content)
251 .ok()
252 .map(EvaluationRulesDeleteError::Status403),
253 404 => serde_json::from_str(&content)
254 .ok()
255 .map(EvaluationRulesDeleteError::Status404),
256 405 => serde_json::from_str(&content)
257 .ok()
258 .map(EvaluationRulesDeleteError::Status405),
259 429 => serde_json::from_str(&content)
260 .ok()
261 .map(EvaluationRulesDeleteError::Status429),
262 500 => serde_json::from_str(&content)
263 .ok()
264 .map(EvaluationRulesDeleteError::Status500),
265 _ => None,
266 }
267 .or_else(|| {
268 serde_json::from_str(&content)
269 .ok()
270 .map(EvaluationRulesDeleteError::UnknownValue)
271 });
272 Err(Error::ResponseError(Box::new(ResponseContent {
273 status,
274 content,
275 entity,
276 headers,
277 })))
278 }
279}
280
281#[bon::builder]
283pub async fn evaluation_rules_get(
284 configuration: &configuration::Configuration,
285 evaluation_rule_id: &str,
286 options: Option<&timvw_rust_runtime::RequestOptions>,
287) -> Result<models::EvaluationRule, Error<EvaluationRulesGetError>> {
288 let p_path_evaluation_rule_id = evaluation_rule_id;
290
291 let uri_str = format!(
292 "{}/api/public/v2/evaluation-rules/{evaluationRuleId}",
293 configuration.base_path,
294 evaluationRuleId = crate::apis::urlencode(p_path_evaluation_rule_id)
295 );
296 let mut req_builder = configuration
297 .client
298 .request(timvw_rust_runtime::Method::GET, &uri_str);
299
300 if let Some(ref user_agent) = configuration.user_agent {
301 req_builder =
302 req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
303 }
304 if let Some(ref auth_conf) = configuration.basic_auth {
305 req_builder = req_builder.basic_auth(
306 &auth_conf.0,
307 auth_conf
308 .1
309 .as_ref()
310 .map(timvw_rust_runtime::ExposeSecret::expose_secret),
311 );
312 };
313
314 if let Some(options) = options {
316 req_builder = req_builder.base(&configuration.base_path).options(options);
317 }
318 let req = req_builder.build()?;
319 let resp = configuration.client.execute(req).await?;
320
321 let status = resp.status();
322 let content_type = resp
323 .headers()
324 .get("content-type")
325 .and_then(|v| v.to_str().ok())
326 .unwrap_or("application/octet-stream");
327 let content_type = super::ContentType::from(content_type);
328
329 if !status.is_client_error() && !status.is_server_error() {
330 let content = resp.text().await?;
331 match content_type {
332 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
333 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EvaluationRule`"))),
334 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EvaluationRule`")))),
335 }
336 } else {
337 let headers = resp.headers().clone();
338 let content = resp.text().await?;
339 let entity: Option<EvaluationRulesGetError> = match status.as_u16() {
340 400 => serde_json::from_str(&content)
341 .ok()
342 .map(EvaluationRulesGetError::Status400),
343 401 => serde_json::from_str(&content)
344 .ok()
345 .map(EvaluationRulesGetError::Status401),
346 403 => serde_json::from_str(&content)
347 .ok()
348 .map(EvaluationRulesGetError::Status403),
349 404 => serde_json::from_str(&content)
350 .ok()
351 .map(EvaluationRulesGetError::Status404),
352 405 => serde_json::from_str(&content)
353 .ok()
354 .map(EvaluationRulesGetError::Status405),
355 429 => serde_json::from_str(&content)
356 .ok()
357 .map(EvaluationRulesGetError::Status429),
358 500 => serde_json::from_str(&content)
359 .ok()
360 .map(EvaluationRulesGetError::Status500),
361 _ => None,
362 }
363 .or_else(|| {
364 serde_json::from_str(&content)
365 .ok()
366 .map(EvaluationRulesGetError::UnknownValue)
367 });
368 Err(Error::ResponseError(Box::new(ResponseContent {
369 status,
370 content,
371 entity,
372 headers,
373 })))
374 }
375}
376
377#[bon::builder]
379pub async fn evaluation_rules_list(
380 configuration: &configuration::Configuration,
381 limit: Option<i64>,
382 cursor: Option<&str>,
383 options: Option<&timvw_rust_runtime::RequestOptions>,
384) -> Result<models::EvaluationRulesPage, Error<EvaluationRulesListError>> {
385 let p_query_limit = limit;
387 let p_query_cursor = cursor;
388
389 let uri_str = format!("{}/api/public/v2/evaluation-rules", configuration.base_path);
390 let mut req_builder = configuration
391 .client
392 .request(timvw_rust_runtime::Method::GET, &uri_str);
393
394 if let Some(ref param_value) = p_query_limit {
395 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
396 }
397 if let Some(ref param_value) = p_query_cursor {
398 req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
399 }
400 if let Some(ref user_agent) = configuration.user_agent {
401 req_builder =
402 req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
403 }
404 if let Some(ref auth_conf) = configuration.basic_auth {
405 req_builder = req_builder.basic_auth(
406 &auth_conf.0,
407 auth_conf
408 .1
409 .as_ref()
410 .map(timvw_rust_runtime::ExposeSecret::expose_secret),
411 );
412 };
413
414 if let Some(options) = options {
416 req_builder = req_builder.base(&configuration.base_path).options(options);
417 }
418 let req = req_builder.build()?;
419 let resp = configuration.client.execute(req).await?;
420
421 let status = resp.status();
422 let content_type = resp
423 .headers()
424 .get("content-type")
425 .and_then(|v| v.to_str().ok())
426 .unwrap_or("application/octet-stream");
427 let content_type = super::ContentType::from(content_type);
428
429 if !status.is_client_error() && !status.is_server_error() {
430 let content = resp.text().await?;
431 match content_type {
432 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
433 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EvaluationRulesPage`"))),
434 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EvaluationRulesPage`")))),
435 }
436 } else {
437 let headers = resp.headers().clone();
438 let content = resp.text().await?;
439 let entity: Option<EvaluationRulesListError> = match status.as_u16() {
440 400 => serde_json::from_str(&content)
441 .ok()
442 .map(EvaluationRulesListError::Status400),
443 401 => serde_json::from_str(&content)
444 .ok()
445 .map(EvaluationRulesListError::Status401),
446 403 => serde_json::from_str(&content)
447 .ok()
448 .map(EvaluationRulesListError::Status403),
449 404 => serde_json::from_str(&content)
450 .ok()
451 .map(EvaluationRulesListError::Status404),
452 405 => serde_json::from_str(&content)
453 .ok()
454 .map(EvaluationRulesListError::Status405),
455 429 => serde_json::from_str(&content)
456 .ok()
457 .map(EvaluationRulesListError::Status429),
458 500 => serde_json::from_str(&content)
459 .ok()
460 .map(EvaluationRulesListError::Status500),
461 _ => None,
462 }
463 .or_else(|| {
464 serde_json::from_str(&content)
465 .ok()
466 .map(EvaluationRulesListError::UnknownValue)
467 });
468 Err(Error::ResponseError(Box::new(ResponseContent {
469 status,
470 content,
471 entity,
472 headers,
473 })))
474 }
475}
476
477#[bon::builder]
479pub async fn evaluation_rules_update(
480 configuration: &configuration::Configuration,
481 evaluation_rule_id: &str,
482 update_evaluation_rule_request: &models::UpdateEvaluationRuleRequest,
483 options: Option<&timvw_rust_runtime::RequestOptions>,
484) -> Result<models::EvaluationRule, Error<EvaluationRulesUpdateError>> {
485 let p_path_evaluation_rule_id = evaluation_rule_id;
487 let p_body_update_evaluation_rule_request = update_evaluation_rule_request;
488
489 let uri_str = format!(
490 "{}/api/public/v2/evaluation-rules/{evaluationRuleId}",
491 configuration.base_path,
492 evaluationRuleId = crate::apis::urlencode(p_path_evaluation_rule_id)
493 );
494 let mut req_builder = configuration
495 .client
496 .request(timvw_rust_runtime::Method::PATCH, &uri_str);
497
498 if let Some(ref user_agent) = configuration.user_agent {
499 req_builder =
500 req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
501 }
502 if let Some(ref auth_conf) = configuration.basic_auth {
503 req_builder = req_builder.basic_auth(
504 &auth_conf.0,
505 auth_conf
506 .1
507 .as_ref()
508 .map(timvw_rust_runtime::ExposeSecret::expose_secret),
509 );
510 };
511 req_builder = req_builder.json(p_body_update_evaluation_rule_request);
512
513 if let Some(options) = options {
515 req_builder = req_builder.base(&configuration.base_path).options(options);
516 }
517 let req = req_builder.build()?;
518 let resp = configuration.client.execute(req).await?;
519
520 let status = resp.status();
521 let content_type = resp
522 .headers()
523 .get("content-type")
524 .and_then(|v| v.to_str().ok())
525 .unwrap_or("application/octet-stream");
526 let content_type = super::ContentType::from(content_type);
527
528 if !status.is_client_error() && !status.is_server_error() {
529 let content = resp.text().await?;
530 match content_type {
531 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
532 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EvaluationRule`"))),
533 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EvaluationRule`")))),
534 }
535 } else {
536 let headers = resp.headers().clone();
537 let content = resp.text().await?;
538 let entity: Option<EvaluationRulesUpdateError> = match status.as_u16() {
539 400 => serde_json::from_str(&content)
540 .ok()
541 .map(EvaluationRulesUpdateError::Status400),
542 401 => serde_json::from_str(&content)
543 .ok()
544 .map(EvaluationRulesUpdateError::Status401),
545 403 => serde_json::from_str(&content)
546 .ok()
547 .map(EvaluationRulesUpdateError::Status403),
548 404 => serde_json::from_str(&content)
549 .ok()
550 .map(EvaluationRulesUpdateError::Status404),
551 405 => serde_json::from_str(&content)
552 .ok()
553 .map(EvaluationRulesUpdateError::Status405),
554 409 => serde_json::from_str(&content)
555 .ok()
556 .map(EvaluationRulesUpdateError::Status409),
557 429 => serde_json::from_str(&content)
558 .ok()
559 .map(EvaluationRulesUpdateError::Status429),
560 500 => serde_json::from_str(&content)
561 .ok()
562 .map(EvaluationRulesUpdateError::Status500),
563 _ => None,
564 }
565 .or_else(|| {
566 serde_json::from_str(&content)
567 .ok()
568 .map(EvaluationRulesUpdateError::UnknownValue)
569 });
570 Err(Error::ResponseError(Box::new(ResponseContent {
571 status,
572 content,
573 entity,
574 headers,
575 })))
576 }
577}