datadog_api_client/datadogV2/api/
api_case_management.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use crate::datadog;
5use async_stream::try_stream;
6use flate2::{
7    write::{GzEncoder, ZlibEncoder},
8    Compression,
9};
10use futures_core::stream::Stream;
11use reqwest::header::{HeaderMap, HeaderValue};
12use serde::{Deserialize, Serialize};
13use std::io::Write;
14
15/// SearchCasesOptionalParams is a struct for passing parameters to the method [`CaseManagementAPI::search_cases`]
16#[non_exhaustive]
17#[derive(Clone, Default, Debug)]
18pub struct SearchCasesOptionalParams {
19    /// Size for a given page. The maximum allowed value is 100.
20    pub page_size: Option<i64>,
21    /// Specific page number to return.
22    pub page_number: Option<i64>,
23    /// Specify which field to sort
24    pub sort_field: Option<crate::datadogV2::model::CaseSortableField>,
25    /// Search query
26    pub filter: Option<String>,
27    /// Specify if order is ascending or not
28    pub sort_asc: Option<bool>,
29}
30
31impl SearchCasesOptionalParams {
32    /// Size for a given page. The maximum allowed value is 100.
33    pub fn page_size(mut self, value: i64) -> Self {
34        self.page_size = Some(value);
35        self
36    }
37    /// Specific page number to return.
38    pub fn page_number(mut self, value: i64) -> Self {
39        self.page_number = Some(value);
40        self
41    }
42    /// Specify which field to sort
43    pub fn sort_field(mut self, value: crate::datadogV2::model::CaseSortableField) -> Self {
44        self.sort_field = Some(value);
45        self
46    }
47    /// Search query
48    pub fn filter(mut self, value: String) -> Self {
49        self.filter = Some(value);
50        self
51    }
52    /// Specify if order is ascending or not
53    pub fn sort_asc(mut self, value: bool) -> Self {
54        self.sort_asc = Some(value);
55        self
56    }
57}
58
59/// ArchiveCaseError is a struct for typed errors of method [`CaseManagementAPI::archive_case`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum ArchiveCaseError {
63    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
64    UnknownValue(serde_json::Value),
65}
66
67/// AssignCaseError is a struct for typed errors of method [`CaseManagementAPI::assign_case`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum AssignCaseError {
71    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
72    UnknownValue(serde_json::Value),
73}
74
75/// CommentCaseError is a struct for typed errors of method [`CaseManagementAPI::comment_case`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum CommentCaseError {
79    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
80    UnknownValue(serde_json::Value),
81}
82
83/// CreateCaseError is a struct for typed errors of method [`CaseManagementAPI::create_case`]
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum CreateCaseError {
87    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
88    UnknownValue(serde_json::Value),
89}
90
91/// CreateProjectError is a struct for typed errors of method [`CaseManagementAPI::create_project`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum CreateProjectError {
95    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
96    UnknownValue(serde_json::Value),
97}
98
99/// DeleteCaseCommentError is a struct for typed errors of method [`CaseManagementAPI::delete_case_comment`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum DeleteCaseCommentError {
103    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
104    UnknownValue(serde_json::Value),
105}
106
107/// DeleteCaseCustomAttributeError is a struct for typed errors of method [`CaseManagementAPI::delete_case_custom_attribute`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum DeleteCaseCustomAttributeError {
111    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
112    UnknownValue(serde_json::Value),
113}
114
115/// DeleteProjectError is a struct for typed errors of method [`CaseManagementAPI::delete_project`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum DeleteProjectError {
119    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
120    UnknownValue(serde_json::Value),
121}
122
123/// GetCaseError is a struct for typed errors of method [`CaseManagementAPI::get_case`]
124#[derive(Debug, Clone, Serialize, Deserialize)]
125#[serde(untagged)]
126pub enum GetCaseError {
127    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
128    UnknownValue(serde_json::Value),
129}
130
131/// GetProjectError is a struct for typed errors of method [`CaseManagementAPI::get_project`]
132#[derive(Debug, Clone, Serialize, Deserialize)]
133#[serde(untagged)]
134pub enum GetProjectError {
135    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
136    UnknownValue(serde_json::Value),
137}
138
139/// GetProjectsError is a struct for typed errors of method [`CaseManagementAPI::get_projects`]
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(untagged)]
142pub enum GetProjectsError {
143    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
144    UnknownValue(serde_json::Value),
145}
146
147/// SearchCasesError is a struct for typed errors of method [`CaseManagementAPI::search_cases`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum SearchCasesError {
151    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
152    UnknownValue(serde_json::Value),
153}
154
155/// UnarchiveCaseError is a struct for typed errors of method [`CaseManagementAPI::unarchive_case`]
156#[derive(Debug, Clone, Serialize, Deserialize)]
157#[serde(untagged)]
158pub enum UnarchiveCaseError {
159    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
160    UnknownValue(serde_json::Value),
161}
162
163/// UnassignCaseError is a struct for typed errors of method [`CaseManagementAPI::unassign_case`]
164#[derive(Debug, Clone, Serialize, Deserialize)]
165#[serde(untagged)]
166pub enum UnassignCaseError {
167    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
168    UnknownValue(serde_json::Value),
169}
170
171/// UpdateAttributesError is a struct for typed errors of method [`CaseManagementAPI::update_attributes`]
172#[derive(Debug, Clone, Serialize, Deserialize)]
173#[serde(untagged)]
174pub enum UpdateAttributesError {
175    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
176    UnknownValue(serde_json::Value),
177}
178
179/// UpdateCaseCustomAttributeError is a struct for typed errors of method [`CaseManagementAPI::update_case_custom_attribute`]
180#[derive(Debug, Clone, Serialize, Deserialize)]
181#[serde(untagged)]
182pub enum UpdateCaseCustomAttributeError {
183    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
184    UnknownValue(serde_json::Value),
185}
186
187/// UpdateCaseDescriptionError is a struct for typed errors of method [`CaseManagementAPI::update_case_description`]
188#[derive(Debug, Clone, Serialize, Deserialize)]
189#[serde(untagged)]
190pub enum UpdateCaseDescriptionError {
191    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
192    UnknownValue(serde_json::Value),
193}
194
195/// UpdateCaseTitleError is a struct for typed errors of method [`CaseManagementAPI::update_case_title`]
196#[derive(Debug, Clone, Serialize, Deserialize)]
197#[serde(untagged)]
198pub enum UpdateCaseTitleError {
199    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
200    UnknownValue(serde_json::Value),
201}
202
203/// UpdatePriorityError is a struct for typed errors of method [`CaseManagementAPI::update_priority`]
204#[derive(Debug, Clone, Serialize, Deserialize)]
205#[serde(untagged)]
206pub enum UpdatePriorityError {
207    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
208    UnknownValue(serde_json::Value),
209}
210
211/// UpdateStatusError is a struct for typed errors of method [`CaseManagementAPI::update_status`]
212#[derive(Debug, Clone, Serialize, Deserialize)]
213#[serde(untagged)]
214pub enum UpdateStatusError {
215    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
216    UnknownValue(serde_json::Value),
217}
218
219/// View and manage cases and projects within Case Management. See the [Case Management page](<https://docs.datadoghq.com/service_management/case_management/>) for more information.
220#[derive(Debug, Clone)]
221pub struct CaseManagementAPI {
222    config: datadog::Configuration,
223    client: reqwest_middleware::ClientWithMiddleware,
224}
225
226impl Default for CaseManagementAPI {
227    fn default() -> Self {
228        Self::with_config(datadog::Configuration::default())
229    }
230}
231
232impl CaseManagementAPI {
233    pub fn new() -> Self {
234        Self::default()
235    }
236    pub fn with_config(config: datadog::Configuration) -> Self {
237        let mut reqwest_client_builder = reqwest::Client::builder();
238
239        if let Some(proxy_url) = &config.proxy_url {
240            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
241            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
242        }
243
244        let mut middleware_client_builder =
245            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
246
247        if config.enable_retry {
248            struct RetryableStatus;
249            impl reqwest_retry::RetryableStrategy for RetryableStatus {
250                fn handle(
251                    &self,
252                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
253                ) -> Option<reqwest_retry::Retryable> {
254                    match res {
255                        Ok(success) => reqwest_retry::default_on_request_success(success),
256                        Err(_) => None,
257                    }
258                }
259            }
260            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
261                .build_with_max_retries(config.max_retries);
262
263            let retry_middleware =
264                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
265                    backoff_policy,
266                    RetryableStatus,
267                );
268
269            middleware_client_builder = middleware_client_builder.with(retry_middleware);
270        }
271
272        let client = middleware_client_builder.build();
273
274        Self { config, client }
275    }
276
277    pub fn with_client_and_config(
278        config: datadog::Configuration,
279        client: reqwest_middleware::ClientWithMiddleware,
280    ) -> Self {
281        Self { config, client }
282    }
283
284    /// Archive case
285    pub async fn archive_case(
286        &self,
287        case_id: String,
288        body: crate::datadogV2::model::CaseEmptyRequest,
289    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<ArchiveCaseError>> {
290        match self.archive_case_with_http_info(case_id, body).await {
291            Ok(response_content) => {
292                if let Some(e) = response_content.entity {
293                    Ok(e)
294                } else {
295                    Err(datadog::Error::Serde(serde::de::Error::custom(
296                        "response content was None",
297                    )))
298                }
299            }
300            Err(err) => Err(err),
301        }
302    }
303
304    /// Archive case
305    pub async fn archive_case_with_http_info(
306        &self,
307        case_id: String,
308        body: crate::datadogV2::model::CaseEmptyRequest,
309    ) -> Result<
310        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
311        datadog::Error<ArchiveCaseError>,
312    > {
313        let local_configuration = &self.config;
314        let operation_id = "v2.archive_case";
315
316        let local_client = &self.client;
317
318        let local_uri_str = format!(
319            "{}/api/v2/cases/{case_id}/archive",
320            local_configuration.get_operation_host(operation_id),
321            case_id = datadog::urlencode(case_id)
322        );
323        let mut local_req_builder =
324            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
325
326        // build headers
327        let mut headers = HeaderMap::new();
328        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
329        headers.insert("Accept", HeaderValue::from_static("application/json"));
330
331        // build user agent
332        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
333            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
334            Err(e) => {
335                log::warn!("Failed to parse user agent header: {e}, falling back to default");
336                headers.insert(
337                    reqwest::header::USER_AGENT,
338                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
339                )
340            }
341        };
342
343        // build auth
344        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
345            headers.insert(
346                "DD-API-KEY",
347                HeaderValue::from_str(local_key.key.as_str())
348                    .expect("failed to parse DD-API-KEY header"),
349            );
350        };
351        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
352            headers.insert(
353                "DD-APPLICATION-KEY",
354                HeaderValue::from_str(local_key.key.as_str())
355                    .expect("failed to parse DD-APPLICATION-KEY header"),
356            );
357        };
358
359        // build body parameters
360        let output = Vec::new();
361        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
362        if body.serialize(&mut ser).is_ok() {
363            if let Some(content_encoding) = headers.get("Content-Encoding") {
364                match content_encoding.to_str().unwrap_or_default() {
365                    "gzip" => {
366                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
367                        let _ = enc.write_all(ser.into_inner().as_slice());
368                        match enc.finish() {
369                            Ok(buf) => {
370                                local_req_builder = local_req_builder.body(buf);
371                            }
372                            Err(e) => return Err(datadog::Error::Io(e)),
373                        }
374                    }
375                    "deflate" => {
376                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
377                        let _ = enc.write_all(ser.into_inner().as_slice());
378                        match enc.finish() {
379                            Ok(buf) => {
380                                local_req_builder = local_req_builder.body(buf);
381                            }
382                            Err(e) => return Err(datadog::Error::Io(e)),
383                        }
384                    }
385                    "zstd1" => {
386                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
387                        let _ = enc.write_all(ser.into_inner().as_slice());
388                        match enc.finish() {
389                            Ok(buf) => {
390                                local_req_builder = local_req_builder.body(buf);
391                            }
392                            Err(e) => return Err(datadog::Error::Io(e)),
393                        }
394                    }
395                    _ => {
396                        local_req_builder = local_req_builder.body(ser.into_inner());
397                    }
398                }
399            } else {
400                local_req_builder = local_req_builder.body(ser.into_inner());
401            }
402        }
403
404        local_req_builder = local_req_builder.headers(headers);
405        let local_req = local_req_builder.build()?;
406        log::debug!("request content: {:?}", local_req.body());
407        let local_resp = local_client.execute(local_req).await?;
408
409        let local_status = local_resp.status();
410        let local_content = local_resp.text().await?;
411        log::debug!("response content: {}", local_content);
412
413        if !local_status.is_client_error() && !local_status.is_server_error() {
414            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
415                Ok(e) => {
416                    return Ok(datadog::ResponseContent {
417                        status: local_status,
418                        content: local_content,
419                        entity: Some(e),
420                    })
421                }
422                Err(e) => return Err(datadog::Error::Serde(e)),
423            };
424        } else {
425            let local_entity: Option<ArchiveCaseError> = serde_json::from_str(&local_content).ok();
426            let local_error = datadog::ResponseContent {
427                status: local_status,
428                content: local_content,
429                entity: local_entity,
430            };
431            Err(datadog::Error::ResponseError(local_error))
432        }
433    }
434
435    /// Assign case to a user
436    pub async fn assign_case(
437        &self,
438        case_id: String,
439        body: crate::datadogV2::model::CaseAssignRequest,
440    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<AssignCaseError>> {
441        match self.assign_case_with_http_info(case_id, body).await {
442            Ok(response_content) => {
443                if let Some(e) = response_content.entity {
444                    Ok(e)
445                } else {
446                    Err(datadog::Error::Serde(serde::de::Error::custom(
447                        "response content was None",
448                    )))
449                }
450            }
451            Err(err) => Err(err),
452        }
453    }
454
455    /// Assign case to a user
456    pub async fn assign_case_with_http_info(
457        &self,
458        case_id: String,
459        body: crate::datadogV2::model::CaseAssignRequest,
460    ) -> Result<
461        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
462        datadog::Error<AssignCaseError>,
463    > {
464        let local_configuration = &self.config;
465        let operation_id = "v2.assign_case";
466
467        let local_client = &self.client;
468
469        let local_uri_str = format!(
470            "{}/api/v2/cases/{case_id}/assign",
471            local_configuration.get_operation_host(operation_id),
472            case_id = datadog::urlencode(case_id)
473        );
474        let mut local_req_builder =
475            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
476
477        // build headers
478        let mut headers = HeaderMap::new();
479        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
480        headers.insert("Accept", HeaderValue::from_static("application/json"));
481
482        // build user agent
483        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
484            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
485            Err(e) => {
486                log::warn!("Failed to parse user agent header: {e}, falling back to default");
487                headers.insert(
488                    reqwest::header::USER_AGENT,
489                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
490                )
491            }
492        };
493
494        // build auth
495        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
496            headers.insert(
497                "DD-API-KEY",
498                HeaderValue::from_str(local_key.key.as_str())
499                    .expect("failed to parse DD-API-KEY header"),
500            );
501        };
502        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
503            headers.insert(
504                "DD-APPLICATION-KEY",
505                HeaderValue::from_str(local_key.key.as_str())
506                    .expect("failed to parse DD-APPLICATION-KEY header"),
507            );
508        };
509
510        // build body parameters
511        let output = Vec::new();
512        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
513        if body.serialize(&mut ser).is_ok() {
514            if let Some(content_encoding) = headers.get("Content-Encoding") {
515                match content_encoding.to_str().unwrap_or_default() {
516                    "gzip" => {
517                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
518                        let _ = enc.write_all(ser.into_inner().as_slice());
519                        match enc.finish() {
520                            Ok(buf) => {
521                                local_req_builder = local_req_builder.body(buf);
522                            }
523                            Err(e) => return Err(datadog::Error::Io(e)),
524                        }
525                    }
526                    "deflate" => {
527                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
528                        let _ = enc.write_all(ser.into_inner().as_slice());
529                        match enc.finish() {
530                            Ok(buf) => {
531                                local_req_builder = local_req_builder.body(buf);
532                            }
533                            Err(e) => return Err(datadog::Error::Io(e)),
534                        }
535                    }
536                    "zstd1" => {
537                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
538                        let _ = enc.write_all(ser.into_inner().as_slice());
539                        match enc.finish() {
540                            Ok(buf) => {
541                                local_req_builder = local_req_builder.body(buf);
542                            }
543                            Err(e) => return Err(datadog::Error::Io(e)),
544                        }
545                    }
546                    _ => {
547                        local_req_builder = local_req_builder.body(ser.into_inner());
548                    }
549                }
550            } else {
551                local_req_builder = local_req_builder.body(ser.into_inner());
552            }
553        }
554
555        local_req_builder = local_req_builder.headers(headers);
556        let local_req = local_req_builder.build()?;
557        log::debug!("request content: {:?}", local_req.body());
558        let local_resp = local_client.execute(local_req).await?;
559
560        let local_status = local_resp.status();
561        let local_content = local_resp.text().await?;
562        log::debug!("response content: {}", local_content);
563
564        if !local_status.is_client_error() && !local_status.is_server_error() {
565            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
566                Ok(e) => {
567                    return Ok(datadog::ResponseContent {
568                        status: local_status,
569                        content: local_content,
570                        entity: Some(e),
571                    })
572                }
573                Err(e) => return Err(datadog::Error::Serde(e)),
574            };
575        } else {
576            let local_entity: Option<AssignCaseError> = serde_json::from_str(&local_content).ok();
577            let local_error = datadog::ResponseContent {
578                status: local_status,
579                content: local_content,
580                entity: local_entity,
581            };
582            Err(datadog::Error::ResponseError(local_error))
583        }
584    }
585
586    /// Comment case
587    pub async fn comment_case(
588        &self,
589        case_id: String,
590        body: crate::datadogV2::model::CaseCommentRequest,
591    ) -> Result<crate::datadogV2::model::TimelineResponse, datadog::Error<CommentCaseError>> {
592        match self.comment_case_with_http_info(case_id, body).await {
593            Ok(response_content) => {
594                if let Some(e) = response_content.entity {
595                    Ok(e)
596                } else {
597                    Err(datadog::Error::Serde(serde::de::Error::custom(
598                        "response content was None",
599                    )))
600                }
601            }
602            Err(err) => Err(err),
603        }
604    }
605
606    /// Comment case
607    pub async fn comment_case_with_http_info(
608        &self,
609        case_id: String,
610        body: crate::datadogV2::model::CaseCommentRequest,
611    ) -> Result<
612        datadog::ResponseContent<crate::datadogV2::model::TimelineResponse>,
613        datadog::Error<CommentCaseError>,
614    > {
615        let local_configuration = &self.config;
616        let operation_id = "v2.comment_case";
617
618        let local_client = &self.client;
619
620        let local_uri_str = format!(
621            "{}/api/v2/cases/{case_id}/comment",
622            local_configuration.get_operation_host(operation_id),
623            case_id = datadog::urlencode(case_id)
624        );
625        let mut local_req_builder =
626            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
627
628        // build headers
629        let mut headers = HeaderMap::new();
630        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
631        headers.insert("Accept", HeaderValue::from_static("application/json"));
632
633        // build user agent
634        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
635            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
636            Err(e) => {
637                log::warn!("Failed to parse user agent header: {e}, falling back to default");
638                headers.insert(
639                    reqwest::header::USER_AGENT,
640                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
641                )
642            }
643        };
644
645        // build auth
646        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
647            headers.insert(
648                "DD-API-KEY",
649                HeaderValue::from_str(local_key.key.as_str())
650                    .expect("failed to parse DD-API-KEY header"),
651            );
652        };
653        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
654            headers.insert(
655                "DD-APPLICATION-KEY",
656                HeaderValue::from_str(local_key.key.as_str())
657                    .expect("failed to parse DD-APPLICATION-KEY header"),
658            );
659        };
660
661        // build body parameters
662        let output = Vec::new();
663        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
664        if body.serialize(&mut ser).is_ok() {
665            if let Some(content_encoding) = headers.get("Content-Encoding") {
666                match content_encoding.to_str().unwrap_or_default() {
667                    "gzip" => {
668                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
669                        let _ = enc.write_all(ser.into_inner().as_slice());
670                        match enc.finish() {
671                            Ok(buf) => {
672                                local_req_builder = local_req_builder.body(buf);
673                            }
674                            Err(e) => return Err(datadog::Error::Io(e)),
675                        }
676                    }
677                    "deflate" => {
678                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
679                        let _ = enc.write_all(ser.into_inner().as_slice());
680                        match enc.finish() {
681                            Ok(buf) => {
682                                local_req_builder = local_req_builder.body(buf);
683                            }
684                            Err(e) => return Err(datadog::Error::Io(e)),
685                        }
686                    }
687                    "zstd1" => {
688                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
689                        let _ = enc.write_all(ser.into_inner().as_slice());
690                        match enc.finish() {
691                            Ok(buf) => {
692                                local_req_builder = local_req_builder.body(buf);
693                            }
694                            Err(e) => return Err(datadog::Error::Io(e)),
695                        }
696                    }
697                    _ => {
698                        local_req_builder = local_req_builder.body(ser.into_inner());
699                    }
700                }
701            } else {
702                local_req_builder = local_req_builder.body(ser.into_inner());
703            }
704        }
705
706        local_req_builder = local_req_builder.headers(headers);
707        let local_req = local_req_builder.build()?;
708        log::debug!("request content: {:?}", local_req.body());
709        let local_resp = local_client.execute(local_req).await?;
710
711        let local_status = local_resp.status();
712        let local_content = local_resp.text().await?;
713        log::debug!("response content: {}", local_content);
714
715        if !local_status.is_client_error() && !local_status.is_server_error() {
716            match serde_json::from_str::<crate::datadogV2::model::TimelineResponse>(&local_content)
717            {
718                Ok(e) => {
719                    return Ok(datadog::ResponseContent {
720                        status: local_status,
721                        content: local_content,
722                        entity: Some(e),
723                    })
724                }
725                Err(e) => return Err(datadog::Error::Serde(e)),
726            };
727        } else {
728            let local_entity: Option<CommentCaseError> = serde_json::from_str(&local_content).ok();
729            let local_error = datadog::ResponseContent {
730                status: local_status,
731                content: local_content,
732                entity: local_entity,
733            };
734            Err(datadog::Error::ResponseError(local_error))
735        }
736    }
737
738    /// Create a Case
739    pub async fn create_case(
740        &self,
741        body: crate::datadogV2::model::CaseCreateRequest,
742    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<CreateCaseError>> {
743        match self.create_case_with_http_info(body).await {
744            Ok(response_content) => {
745                if let Some(e) = response_content.entity {
746                    Ok(e)
747                } else {
748                    Err(datadog::Error::Serde(serde::de::Error::custom(
749                        "response content was None",
750                    )))
751                }
752            }
753            Err(err) => Err(err),
754        }
755    }
756
757    /// Create a Case
758    pub async fn create_case_with_http_info(
759        &self,
760        body: crate::datadogV2::model::CaseCreateRequest,
761    ) -> Result<
762        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
763        datadog::Error<CreateCaseError>,
764    > {
765        let local_configuration = &self.config;
766        let operation_id = "v2.create_case";
767
768        let local_client = &self.client;
769
770        let local_uri_str = format!(
771            "{}/api/v2/cases",
772            local_configuration.get_operation_host(operation_id)
773        );
774        let mut local_req_builder =
775            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
776
777        // build headers
778        let mut headers = HeaderMap::new();
779        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
780        headers.insert("Accept", HeaderValue::from_static("application/json"));
781
782        // build user agent
783        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
784            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
785            Err(e) => {
786                log::warn!("Failed to parse user agent header: {e}, falling back to default");
787                headers.insert(
788                    reqwest::header::USER_AGENT,
789                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
790                )
791            }
792        };
793
794        // build auth
795        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
796            headers.insert(
797                "DD-API-KEY",
798                HeaderValue::from_str(local_key.key.as_str())
799                    .expect("failed to parse DD-API-KEY header"),
800            );
801        };
802        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
803            headers.insert(
804                "DD-APPLICATION-KEY",
805                HeaderValue::from_str(local_key.key.as_str())
806                    .expect("failed to parse DD-APPLICATION-KEY header"),
807            );
808        };
809
810        // build body parameters
811        let output = Vec::new();
812        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
813        if body.serialize(&mut ser).is_ok() {
814            if let Some(content_encoding) = headers.get("Content-Encoding") {
815                match content_encoding.to_str().unwrap_or_default() {
816                    "gzip" => {
817                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
818                        let _ = enc.write_all(ser.into_inner().as_slice());
819                        match enc.finish() {
820                            Ok(buf) => {
821                                local_req_builder = local_req_builder.body(buf);
822                            }
823                            Err(e) => return Err(datadog::Error::Io(e)),
824                        }
825                    }
826                    "deflate" => {
827                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
828                        let _ = enc.write_all(ser.into_inner().as_slice());
829                        match enc.finish() {
830                            Ok(buf) => {
831                                local_req_builder = local_req_builder.body(buf);
832                            }
833                            Err(e) => return Err(datadog::Error::Io(e)),
834                        }
835                    }
836                    "zstd1" => {
837                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
838                        let _ = enc.write_all(ser.into_inner().as_slice());
839                        match enc.finish() {
840                            Ok(buf) => {
841                                local_req_builder = local_req_builder.body(buf);
842                            }
843                            Err(e) => return Err(datadog::Error::Io(e)),
844                        }
845                    }
846                    _ => {
847                        local_req_builder = local_req_builder.body(ser.into_inner());
848                    }
849                }
850            } else {
851                local_req_builder = local_req_builder.body(ser.into_inner());
852            }
853        }
854
855        local_req_builder = local_req_builder.headers(headers);
856        let local_req = local_req_builder.build()?;
857        log::debug!("request content: {:?}", local_req.body());
858        let local_resp = local_client.execute(local_req).await?;
859
860        let local_status = local_resp.status();
861        let local_content = local_resp.text().await?;
862        log::debug!("response content: {}", local_content);
863
864        if !local_status.is_client_error() && !local_status.is_server_error() {
865            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
866                Ok(e) => {
867                    return Ok(datadog::ResponseContent {
868                        status: local_status,
869                        content: local_content,
870                        entity: Some(e),
871                    })
872                }
873                Err(e) => return Err(datadog::Error::Serde(e)),
874            };
875        } else {
876            let local_entity: Option<CreateCaseError> = serde_json::from_str(&local_content).ok();
877            let local_error = datadog::ResponseContent {
878                status: local_status,
879                content: local_content,
880                entity: local_entity,
881            };
882            Err(datadog::Error::ResponseError(local_error))
883        }
884    }
885
886    /// Create a project.
887    pub async fn create_project(
888        &self,
889        body: crate::datadogV2::model::ProjectCreateRequest,
890    ) -> Result<crate::datadogV2::model::ProjectResponse, datadog::Error<CreateProjectError>> {
891        match self.create_project_with_http_info(body).await {
892            Ok(response_content) => {
893                if let Some(e) = response_content.entity {
894                    Ok(e)
895                } else {
896                    Err(datadog::Error::Serde(serde::de::Error::custom(
897                        "response content was None",
898                    )))
899                }
900            }
901            Err(err) => Err(err),
902        }
903    }
904
905    /// Create a project.
906    pub async fn create_project_with_http_info(
907        &self,
908        body: crate::datadogV2::model::ProjectCreateRequest,
909    ) -> Result<
910        datadog::ResponseContent<crate::datadogV2::model::ProjectResponse>,
911        datadog::Error<CreateProjectError>,
912    > {
913        let local_configuration = &self.config;
914        let operation_id = "v2.create_project";
915
916        let local_client = &self.client;
917
918        let local_uri_str = format!(
919            "{}/api/v2/cases/projects",
920            local_configuration.get_operation_host(operation_id)
921        );
922        let mut local_req_builder =
923            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
924
925        // build headers
926        let mut headers = HeaderMap::new();
927        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
928        headers.insert("Accept", HeaderValue::from_static("application/json"));
929
930        // build user agent
931        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
932            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
933            Err(e) => {
934                log::warn!("Failed to parse user agent header: {e}, falling back to default");
935                headers.insert(
936                    reqwest::header::USER_AGENT,
937                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
938                )
939            }
940        };
941
942        // build auth
943        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
944            headers.insert(
945                "DD-API-KEY",
946                HeaderValue::from_str(local_key.key.as_str())
947                    .expect("failed to parse DD-API-KEY header"),
948            );
949        };
950        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
951            headers.insert(
952                "DD-APPLICATION-KEY",
953                HeaderValue::from_str(local_key.key.as_str())
954                    .expect("failed to parse DD-APPLICATION-KEY header"),
955            );
956        };
957
958        // build body parameters
959        let output = Vec::new();
960        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
961        if body.serialize(&mut ser).is_ok() {
962            if let Some(content_encoding) = headers.get("Content-Encoding") {
963                match content_encoding.to_str().unwrap_or_default() {
964                    "gzip" => {
965                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
966                        let _ = enc.write_all(ser.into_inner().as_slice());
967                        match enc.finish() {
968                            Ok(buf) => {
969                                local_req_builder = local_req_builder.body(buf);
970                            }
971                            Err(e) => return Err(datadog::Error::Io(e)),
972                        }
973                    }
974                    "deflate" => {
975                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
976                        let _ = enc.write_all(ser.into_inner().as_slice());
977                        match enc.finish() {
978                            Ok(buf) => {
979                                local_req_builder = local_req_builder.body(buf);
980                            }
981                            Err(e) => return Err(datadog::Error::Io(e)),
982                        }
983                    }
984                    "zstd1" => {
985                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
986                        let _ = enc.write_all(ser.into_inner().as_slice());
987                        match enc.finish() {
988                            Ok(buf) => {
989                                local_req_builder = local_req_builder.body(buf);
990                            }
991                            Err(e) => return Err(datadog::Error::Io(e)),
992                        }
993                    }
994                    _ => {
995                        local_req_builder = local_req_builder.body(ser.into_inner());
996                    }
997                }
998            } else {
999                local_req_builder = local_req_builder.body(ser.into_inner());
1000            }
1001        }
1002
1003        local_req_builder = local_req_builder.headers(headers);
1004        let local_req = local_req_builder.build()?;
1005        log::debug!("request content: {:?}", local_req.body());
1006        let local_resp = local_client.execute(local_req).await?;
1007
1008        let local_status = local_resp.status();
1009        let local_content = local_resp.text().await?;
1010        log::debug!("response content: {}", local_content);
1011
1012        if !local_status.is_client_error() && !local_status.is_server_error() {
1013            match serde_json::from_str::<crate::datadogV2::model::ProjectResponse>(&local_content) {
1014                Ok(e) => {
1015                    return Ok(datadog::ResponseContent {
1016                        status: local_status,
1017                        content: local_content,
1018                        entity: Some(e),
1019                    })
1020                }
1021                Err(e) => return Err(datadog::Error::Serde(e)),
1022            };
1023        } else {
1024            let local_entity: Option<CreateProjectError> =
1025                serde_json::from_str(&local_content).ok();
1026            let local_error = datadog::ResponseContent {
1027                status: local_status,
1028                content: local_content,
1029                entity: local_entity,
1030            };
1031            Err(datadog::Error::ResponseError(local_error))
1032        }
1033    }
1034
1035    /// Delete case comment
1036    pub async fn delete_case_comment(
1037        &self,
1038        case_id: String,
1039        cell_id: String,
1040    ) -> Result<(), datadog::Error<DeleteCaseCommentError>> {
1041        match self
1042            .delete_case_comment_with_http_info(case_id, cell_id)
1043            .await
1044        {
1045            Ok(_) => Ok(()),
1046            Err(err) => Err(err),
1047        }
1048    }
1049
1050    /// Delete case comment
1051    pub async fn delete_case_comment_with_http_info(
1052        &self,
1053        case_id: String,
1054        cell_id: String,
1055    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCaseCommentError>> {
1056        let local_configuration = &self.config;
1057        let operation_id = "v2.delete_case_comment";
1058
1059        let local_client = &self.client;
1060
1061        let local_uri_str = format!(
1062            "{}/api/v2/cases/{case_id}/comment/{cell_id}",
1063            local_configuration.get_operation_host(operation_id),
1064            case_id = datadog::urlencode(case_id),
1065            cell_id = datadog::urlencode(cell_id)
1066        );
1067        let mut local_req_builder =
1068            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1069
1070        // build headers
1071        let mut headers = HeaderMap::new();
1072        headers.insert("Accept", HeaderValue::from_static("*/*"));
1073
1074        // build user agent
1075        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1076            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1077            Err(e) => {
1078                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1079                headers.insert(
1080                    reqwest::header::USER_AGENT,
1081                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1082                )
1083            }
1084        };
1085
1086        // build auth
1087        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1088            headers.insert(
1089                "DD-API-KEY",
1090                HeaderValue::from_str(local_key.key.as_str())
1091                    .expect("failed to parse DD-API-KEY header"),
1092            );
1093        };
1094        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1095            headers.insert(
1096                "DD-APPLICATION-KEY",
1097                HeaderValue::from_str(local_key.key.as_str())
1098                    .expect("failed to parse DD-APPLICATION-KEY header"),
1099            );
1100        };
1101
1102        local_req_builder = local_req_builder.headers(headers);
1103        let local_req = local_req_builder.build()?;
1104        log::debug!("request content: {:?}", local_req.body());
1105        let local_resp = local_client.execute(local_req).await?;
1106
1107        let local_status = local_resp.status();
1108        let local_content = local_resp.text().await?;
1109        log::debug!("response content: {}", local_content);
1110
1111        if !local_status.is_client_error() && !local_status.is_server_error() {
1112            Ok(datadog::ResponseContent {
1113                status: local_status,
1114                content: local_content,
1115                entity: None,
1116            })
1117        } else {
1118            let local_entity: Option<DeleteCaseCommentError> =
1119                serde_json::from_str(&local_content).ok();
1120            let local_error = datadog::ResponseContent {
1121                status: local_status,
1122                content: local_content,
1123                entity: local_entity,
1124            };
1125            Err(datadog::Error::ResponseError(local_error))
1126        }
1127    }
1128
1129    /// Delete custom attribute from case
1130    pub async fn delete_case_custom_attribute(
1131        &self,
1132        case_id: String,
1133        custom_attribute_key: String,
1134    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<DeleteCaseCustomAttributeError>>
1135    {
1136        match self
1137            .delete_case_custom_attribute_with_http_info(case_id, custom_attribute_key)
1138            .await
1139        {
1140            Ok(response_content) => {
1141                if let Some(e) = response_content.entity {
1142                    Ok(e)
1143                } else {
1144                    Err(datadog::Error::Serde(serde::de::Error::custom(
1145                        "response content was None",
1146                    )))
1147                }
1148            }
1149            Err(err) => Err(err),
1150        }
1151    }
1152
1153    /// Delete custom attribute from case
1154    pub async fn delete_case_custom_attribute_with_http_info(
1155        &self,
1156        case_id: String,
1157        custom_attribute_key: String,
1158    ) -> Result<
1159        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
1160        datadog::Error<DeleteCaseCustomAttributeError>,
1161    > {
1162        let local_configuration = &self.config;
1163        let operation_id = "v2.delete_case_custom_attribute";
1164
1165        let local_client = &self.client;
1166
1167        let local_uri_str = format!(
1168            "{}/api/v2/cases/{case_id}/custom_attributes/{custom_attribute_key}",
1169            local_configuration.get_operation_host(operation_id),
1170            case_id = datadog::urlencode(case_id),
1171            custom_attribute_key = datadog::urlencode(custom_attribute_key)
1172        );
1173        let mut local_req_builder =
1174            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1175
1176        // build headers
1177        let mut headers = HeaderMap::new();
1178        headers.insert("Accept", HeaderValue::from_static("application/json"));
1179
1180        // build user agent
1181        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1182            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1183            Err(e) => {
1184                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1185                headers.insert(
1186                    reqwest::header::USER_AGENT,
1187                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1188                )
1189            }
1190        };
1191
1192        // build auth
1193        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1194            headers.insert(
1195                "DD-API-KEY",
1196                HeaderValue::from_str(local_key.key.as_str())
1197                    .expect("failed to parse DD-API-KEY header"),
1198            );
1199        };
1200        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1201            headers.insert(
1202                "DD-APPLICATION-KEY",
1203                HeaderValue::from_str(local_key.key.as_str())
1204                    .expect("failed to parse DD-APPLICATION-KEY header"),
1205            );
1206        };
1207
1208        local_req_builder = local_req_builder.headers(headers);
1209        let local_req = local_req_builder.build()?;
1210        log::debug!("request content: {:?}", local_req.body());
1211        let local_resp = local_client.execute(local_req).await?;
1212
1213        let local_status = local_resp.status();
1214        let local_content = local_resp.text().await?;
1215        log::debug!("response content: {}", local_content);
1216
1217        if !local_status.is_client_error() && !local_status.is_server_error() {
1218            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
1219                Ok(e) => {
1220                    return Ok(datadog::ResponseContent {
1221                        status: local_status,
1222                        content: local_content,
1223                        entity: Some(e),
1224                    })
1225                }
1226                Err(e) => return Err(datadog::Error::Serde(e)),
1227            };
1228        } else {
1229            let local_entity: Option<DeleteCaseCustomAttributeError> =
1230                serde_json::from_str(&local_content).ok();
1231            let local_error = datadog::ResponseContent {
1232                status: local_status,
1233                content: local_content,
1234                entity: local_entity,
1235            };
1236            Err(datadog::Error::ResponseError(local_error))
1237        }
1238    }
1239
1240    /// Remove a project using the project's `id`.
1241    pub async fn delete_project(
1242        &self,
1243        project_id: String,
1244    ) -> Result<(), datadog::Error<DeleteProjectError>> {
1245        match self.delete_project_with_http_info(project_id).await {
1246            Ok(_) => Ok(()),
1247            Err(err) => Err(err),
1248        }
1249    }
1250
1251    /// Remove a project using the project's `id`.
1252    pub async fn delete_project_with_http_info(
1253        &self,
1254        project_id: String,
1255    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteProjectError>> {
1256        let local_configuration = &self.config;
1257        let operation_id = "v2.delete_project";
1258
1259        let local_client = &self.client;
1260
1261        let local_uri_str = format!(
1262            "{}/api/v2/cases/projects/{project_id}",
1263            local_configuration.get_operation_host(operation_id),
1264            project_id = datadog::urlencode(project_id)
1265        );
1266        let mut local_req_builder =
1267            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1268
1269        // build headers
1270        let mut headers = HeaderMap::new();
1271        headers.insert("Accept", HeaderValue::from_static("*/*"));
1272
1273        // build user agent
1274        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1275            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1276            Err(e) => {
1277                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1278                headers.insert(
1279                    reqwest::header::USER_AGENT,
1280                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1281                )
1282            }
1283        };
1284
1285        // build auth
1286        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1287            headers.insert(
1288                "DD-API-KEY",
1289                HeaderValue::from_str(local_key.key.as_str())
1290                    .expect("failed to parse DD-API-KEY header"),
1291            );
1292        };
1293        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1294            headers.insert(
1295                "DD-APPLICATION-KEY",
1296                HeaderValue::from_str(local_key.key.as_str())
1297                    .expect("failed to parse DD-APPLICATION-KEY header"),
1298            );
1299        };
1300
1301        local_req_builder = local_req_builder.headers(headers);
1302        let local_req = local_req_builder.build()?;
1303        log::debug!("request content: {:?}", local_req.body());
1304        let local_resp = local_client.execute(local_req).await?;
1305
1306        let local_status = local_resp.status();
1307        let local_content = local_resp.text().await?;
1308        log::debug!("response content: {}", local_content);
1309
1310        if !local_status.is_client_error() && !local_status.is_server_error() {
1311            Ok(datadog::ResponseContent {
1312                status: local_status,
1313                content: local_content,
1314                entity: None,
1315            })
1316        } else {
1317            let local_entity: Option<DeleteProjectError> =
1318                serde_json::from_str(&local_content).ok();
1319            let local_error = datadog::ResponseContent {
1320                status: local_status,
1321                content: local_content,
1322                entity: local_entity,
1323            };
1324            Err(datadog::Error::ResponseError(local_error))
1325        }
1326    }
1327
1328    /// Get the details of case by `case_id`
1329    pub async fn get_case(
1330        &self,
1331        case_id: String,
1332    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<GetCaseError>> {
1333        match self.get_case_with_http_info(case_id).await {
1334            Ok(response_content) => {
1335                if let Some(e) = response_content.entity {
1336                    Ok(e)
1337                } else {
1338                    Err(datadog::Error::Serde(serde::de::Error::custom(
1339                        "response content was None",
1340                    )))
1341                }
1342            }
1343            Err(err) => Err(err),
1344        }
1345    }
1346
1347    /// Get the details of case by `case_id`
1348    pub async fn get_case_with_http_info(
1349        &self,
1350        case_id: String,
1351    ) -> Result<
1352        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
1353        datadog::Error<GetCaseError>,
1354    > {
1355        let local_configuration = &self.config;
1356        let operation_id = "v2.get_case";
1357
1358        let local_client = &self.client;
1359
1360        let local_uri_str = format!(
1361            "{}/api/v2/cases/{case_id}",
1362            local_configuration.get_operation_host(operation_id),
1363            case_id = datadog::urlencode(case_id)
1364        );
1365        let mut local_req_builder =
1366            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1367
1368        // build headers
1369        let mut headers = HeaderMap::new();
1370        headers.insert("Accept", HeaderValue::from_static("application/json"));
1371
1372        // build user agent
1373        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1374            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1375            Err(e) => {
1376                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1377                headers.insert(
1378                    reqwest::header::USER_AGENT,
1379                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1380                )
1381            }
1382        };
1383
1384        // build auth
1385        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1386            headers.insert(
1387                "DD-API-KEY",
1388                HeaderValue::from_str(local_key.key.as_str())
1389                    .expect("failed to parse DD-API-KEY header"),
1390            );
1391        };
1392        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1393            headers.insert(
1394                "DD-APPLICATION-KEY",
1395                HeaderValue::from_str(local_key.key.as_str())
1396                    .expect("failed to parse DD-APPLICATION-KEY header"),
1397            );
1398        };
1399
1400        local_req_builder = local_req_builder.headers(headers);
1401        let local_req = local_req_builder.build()?;
1402        log::debug!("request content: {:?}", local_req.body());
1403        let local_resp = local_client.execute(local_req).await?;
1404
1405        let local_status = local_resp.status();
1406        let local_content = local_resp.text().await?;
1407        log::debug!("response content: {}", local_content);
1408
1409        if !local_status.is_client_error() && !local_status.is_server_error() {
1410            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
1411                Ok(e) => {
1412                    return Ok(datadog::ResponseContent {
1413                        status: local_status,
1414                        content: local_content,
1415                        entity: Some(e),
1416                    })
1417                }
1418                Err(e) => return Err(datadog::Error::Serde(e)),
1419            };
1420        } else {
1421            let local_entity: Option<GetCaseError> = serde_json::from_str(&local_content).ok();
1422            let local_error = datadog::ResponseContent {
1423                status: local_status,
1424                content: local_content,
1425                entity: local_entity,
1426            };
1427            Err(datadog::Error::ResponseError(local_error))
1428        }
1429    }
1430
1431    /// Get the details of a project by `project_id`.
1432    pub async fn get_project(
1433        &self,
1434        project_id: String,
1435    ) -> Result<crate::datadogV2::model::ProjectResponse, datadog::Error<GetProjectError>> {
1436        match self.get_project_with_http_info(project_id).await {
1437            Ok(response_content) => {
1438                if let Some(e) = response_content.entity {
1439                    Ok(e)
1440                } else {
1441                    Err(datadog::Error::Serde(serde::de::Error::custom(
1442                        "response content was None",
1443                    )))
1444                }
1445            }
1446            Err(err) => Err(err),
1447        }
1448    }
1449
1450    /// Get the details of a project by `project_id`.
1451    pub async fn get_project_with_http_info(
1452        &self,
1453        project_id: String,
1454    ) -> Result<
1455        datadog::ResponseContent<crate::datadogV2::model::ProjectResponse>,
1456        datadog::Error<GetProjectError>,
1457    > {
1458        let local_configuration = &self.config;
1459        let operation_id = "v2.get_project";
1460
1461        let local_client = &self.client;
1462
1463        let local_uri_str = format!(
1464            "{}/api/v2/cases/projects/{project_id}",
1465            local_configuration.get_operation_host(operation_id),
1466            project_id = datadog::urlencode(project_id)
1467        );
1468        let mut local_req_builder =
1469            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1470
1471        // build headers
1472        let mut headers = HeaderMap::new();
1473        headers.insert("Accept", HeaderValue::from_static("application/json"));
1474
1475        // build user agent
1476        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1477            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1478            Err(e) => {
1479                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1480                headers.insert(
1481                    reqwest::header::USER_AGENT,
1482                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1483                )
1484            }
1485        };
1486
1487        // build auth
1488        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1489            headers.insert(
1490                "DD-API-KEY",
1491                HeaderValue::from_str(local_key.key.as_str())
1492                    .expect("failed to parse DD-API-KEY header"),
1493            );
1494        };
1495        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1496            headers.insert(
1497                "DD-APPLICATION-KEY",
1498                HeaderValue::from_str(local_key.key.as_str())
1499                    .expect("failed to parse DD-APPLICATION-KEY header"),
1500            );
1501        };
1502
1503        local_req_builder = local_req_builder.headers(headers);
1504        let local_req = local_req_builder.build()?;
1505        log::debug!("request content: {:?}", local_req.body());
1506        let local_resp = local_client.execute(local_req).await?;
1507
1508        let local_status = local_resp.status();
1509        let local_content = local_resp.text().await?;
1510        log::debug!("response content: {}", local_content);
1511
1512        if !local_status.is_client_error() && !local_status.is_server_error() {
1513            match serde_json::from_str::<crate::datadogV2::model::ProjectResponse>(&local_content) {
1514                Ok(e) => {
1515                    return Ok(datadog::ResponseContent {
1516                        status: local_status,
1517                        content: local_content,
1518                        entity: Some(e),
1519                    })
1520                }
1521                Err(e) => return Err(datadog::Error::Serde(e)),
1522            };
1523        } else {
1524            let local_entity: Option<GetProjectError> = serde_json::from_str(&local_content).ok();
1525            let local_error = datadog::ResponseContent {
1526                status: local_status,
1527                content: local_content,
1528                entity: local_entity,
1529            };
1530            Err(datadog::Error::ResponseError(local_error))
1531        }
1532    }
1533
1534    /// Get all projects.
1535    pub async fn get_projects(
1536        &self,
1537    ) -> Result<crate::datadogV2::model::ProjectsResponse, datadog::Error<GetProjectsError>> {
1538        match self.get_projects_with_http_info().await {
1539            Ok(response_content) => {
1540                if let Some(e) = response_content.entity {
1541                    Ok(e)
1542                } else {
1543                    Err(datadog::Error::Serde(serde::de::Error::custom(
1544                        "response content was None",
1545                    )))
1546                }
1547            }
1548            Err(err) => Err(err),
1549        }
1550    }
1551
1552    /// Get all projects.
1553    pub async fn get_projects_with_http_info(
1554        &self,
1555    ) -> Result<
1556        datadog::ResponseContent<crate::datadogV2::model::ProjectsResponse>,
1557        datadog::Error<GetProjectsError>,
1558    > {
1559        let local_configuration = &self.config;
1560        let operation_id = "v2.get_projects";
1561
1562        let local_client = &self.client;
1563
1564        let local_uri_str = format!(
1565            "{}/api/v2/cases/projects",
1566            local_configuration.get_operation_host(operation_id)
1567        );
1568        let mut local_req_builder =
1569            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1570
1571        // build headers
1572        let mut headers = HeaderMap::new();
1573        headers.insert("Accept", HeaderValue::from_static("application/json"));
1574
1575        // build user agent
1576        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1577            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1578            Err(e) => {
1579                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1580                headers.insert(
1581                    reqwest::header::USER_AGENT,
1582                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1583                )
1584            }
1585        };
1586
1587        // build auth
1588        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1589            headers.insert(
1590                "DD-API-KEY",
1591                HeaderValue::from_str(local_key.key.as_str())
1592                    .expect("failed to parse DD-API-KEY header"),
1593            );
1594        };
1595        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1596            headers.insert(
1597                "DD-APPLICATION-KEY",
1598                HeaderValue::from_str(local_key.key.as_str())
1599                    .expect("failed to parse DD-APPLICATION-KEY header"),
1600            );
1601        };
1602
1603        local_req_builder = local_req_builder.headers(headers);
1604        let local_req = local_req_builder.build()?;
1605        log::debug!("request content: {:?}", local_req.body());
1606        let local_resp = local_client.execute(local_req).await?;
1607
1608        let local_status = local_resp.status();
1609        let local_content = local_resp.text().await?;
1610        log::debug!("response content: {}", local_content);
1611
1612        if !local_status.is_client_error() && !local_status.is_server_error() {
1613            match serde_json::from_str::<crate::datadogV2::model::ProjectsResponse>(&local_content)
1614            {
1615                Ok(e) => {
1616                    return Ok(datadog::ResponseContent {
1617                        status: local_status,
1618                        content: local_content,
1619                        entity: Some(e),
1620                    })
1621                }
1622                Err(e) => return Err(datadog::Error::Serde(e)),
1623            };
1624        } else {
1625            let local_entity: Option<GetProjectsError> = serde_json::from_str(&local_content).ok();
1626            let local_error = datadog::ResponseContent {
1627                status: local_status,
1628                content: local_content,
1629                entity: local_entity,
1630            };
1631            Err(datadog::Error::ResponseError(local_error))
1632        }
1633    }
1634
1635    /// Search cases.
1636    pub async fn search_cases(
1637        &self,
1638        params: SearchCasesOptionalParams,
1639    ) -> Result<crate::datadogV2::model::CasesResponse, datadog::Error<SearchCasesError>> {
1640        match self.search_cases_with_http_info(params).await {
1641            Ok(response_content) => {
1642                if let Some(e) = response_content.entity {
1643                    Ok(e)
1644                } else {
1645                    Err(datadog::Error::Serde(serde::de::Error::custom(
1646                        "response content was None",
1647                    )))
1648                }
1649            }
1650            Err(err) => Err(err),
1651        }
1652    }
1653
1654    pub fn search_cases_with_pagination(
1655        &self,
1656        mut params: SearchCasesOptionalParams,
1657    ) -> impl Stream<Item = Result<crate::datadogV2::model::Case, datadog::Error<SearchCasesError>>> + '_
1658    {
1659        try_stream! {
1660            let mut page_size: i64 = 10;
1661            if params.page_size.is_none() {
1662                params.page_size = Some(page_size);
1663            } else {
1664                page_size = params.page_size.unwrap().clone();
1665            }
1666            if params.page_number.is_none() {
1667                params.page_number = Some(0);
1668            }
1669            loop {
1670                let resp = self.search_cases(params.clone()).await?;
1671                let Some(data) = resp.data else { break };
1672
1673                let r = data;
1674                let count = r.len();
1675                for team in r {
1676                    yield team;
1677                }
1678
1679                if count < page_size as usize {
1680                    break;
1681                }
1682                params.page_number = Some(params.page_number.unwrap() + 1);
1683            }
1684        }
1685    }
1686
1687    /// Search cases.
1688    pub async fn search_cases_with_http_info(
1689        &self,
1690        params: SearchCasesOptionalParams,
1691    ) -> Result<
1692        datadog::ResponseContent<crate::datadogV2::model::CasesResponse>,
1693        datadog::Error<SearchCasesError>,
1694    > {
1695        let local_configuration = &self.config;
1696        let operation_id = "v2.search_cases";
1697
1698        // unbox and build optional parameters
1699        let page_size = params.page_size;
1700        let page_number = params.page_number;
1701        let sort_field = params.sort_field;
1702        let filter = params.filter;
1703        let sort_asc = params.sort_asc;
1704
1705        let local_client = &self.client;
1706
1707        let local_uri_str = format!(
1708            "{}/api/v2/cases",
1709            local_configuration.get_operation_host(operation_id)
1710        );
1711        let mut local_req_builder =
1712            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1713
1714        if let Some(ref local_query_param) = page_size {
1715            local_req_builder =
1716                local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1717        };
1718        if let Some(ref local_query_param) = page_number {
1719            local_req_builder =
1720                local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
1721        };
1722        if let Some(ref local_query_param) = sort_field {
1723            local_req_builder =
1724                local_req_builder.query(&[("sort[field]", &local_query_param.to_string())]);
1725        };
1726        if let Some(ref local_query_param) = filter {
1727            local_req_builder =
1728                local_req_builder.query(&[("filter", &local_query_param.to_string())]);
1729        };
1730        if let Some(ref local_query_param) = sort_asc {
1731            local_req_builder =
1732                local_req_builder.query(&[("sort[asc]", &local_query_param.to_string())]);
1733        };
1734
1735        // build headers
1736        let mut headers = HeaderMap::new();
1737        headers.insert("Accept", HeaderValue::from_static("application/json"));
1738
1739        // build user agent
1740        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1741            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1742            Err(e) => {
1743                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1744                headers.insert(
1745                    reqwest::header::USER_AGENT,
1746                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1747                )
1748            }
1749        };
1750
1751        // build auth
1752        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1753            headers.insert(
1754                "DD-API-KEY",
1755                HeaderValue::from_str(local_key.key.as_str())
1756                    .expect("failed to parse DD-API-KEY header"),
1757            );
1758        };
1759        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1760            headers.insert(
1761                "DD-APPLICATION-KEY",
1762                HeaderValue::from_str(local_key.key.as_str())
1763                    .expect("failed to parse DD-APPLICATION-KEY header"),
1764            );
1765        };
1766
1767        local_req_builder = local_req_builder.headers(headers);
1768        let local_req = local_req_builder.build()?;
1769        log::debug!("request content: {:?}", local_req.body());
1770        let local_resp = local_client.execute(local_req).await?;
1771
1772        let local_status = local_resp.status();
1773        let local_content = local_resp.text().await?;
1774        log::debug!("response content: {}", local_content);
1775
1776        if !local_status.is_client_error() && !local_status.is_server_error() {
1777            match serde_json::from_str::<crate::datadogV2::model::CasesResponse>(&local_content) {
1778                Ok(e) => {
1779                    return Ok(datadog::ResponseContent {
1780                        status: local_status,
1781                        content: local_content,
1782                        entity: Some(e),
1783                    })
1784                }
1785                Err(e) => return Err(datadog::Error::Serde(e)),
1786            };
1787        } else {
1788            let local_entity: Option<SearchCasesError> = serde_json::from_str(&local_content).ok();
1789            let local_error = datadog::ResponseContent {
1790                status: local_status,
1791                content: local_content,
1792                entity: local_entity,
1793            };
1794            Err(datadog::Error::ResponseError(local_error))
1795        }
1796    }
1797
1798    /// Unarchive case
1799    pub async fn unarchive_case(
1800        &self,
1801        case_id: String,
1802        body: crate::datadogV2::model::CaseEmptyRequest,
1803    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UnarchiveCaseError>> {
1804        match self.unarchive_case_with_http_info(case_id, body).await {
1805            Ok(response_content) => {
1806                if let Some(e) = response_content.entity {
1807                    Ok(e)
1808                } else {
1809                    Err(datadog::Error::Serde(serde::de::Error::custom(
1810                        "response content was None",
1811                    )))
1812                }
1813            }
1814            Err(err) => Err(err),
1815        }
1816    }
1817
1818    /// Unarchive case
1819    pub async fn unarchive_case_with_http_info(
1820        &self,
1821        case_id: String,
1822        body: crate::datadogV2::model::CaseEmptyRequest,
1823    ) -> Result<
1824        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
1825        datadog::Error<UnarchiveCaseError>,
1826    > {
1827        let local_configuration = &self.config;
1828        let operation_id = "v2.unarchive_case";
1829
1830        let local_client = &self.client;
1831
1832        let local_uri_str = format!(
1833            "{}/api/v2/cases/{case_id}/unarchive",
1834            local_configuration.get_operation_host(operation_id),
1835            case_id = datadog::urlencode(case_id)
1836        );
1837        let mut local_req_builder =
1838            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1839
1840        // build headers
1841        let mut headers = HeaderMap::new();
1842        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1843        headers.insert("Accept", HeaderValue::from_static("application/json"));
1844
1845        // build user agent
1846        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1847            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1848            Err(e) => {
1849                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1850                headers.insert(
1851                    reqwest::header::USER_AGENT,
1852                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1853                )
1854            }
1855        };
1856
1857        // build auth
1858        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1859            headers.insert(
1860                "DD-API-KEY",
1861                HeaderValue::from_str(local_key.key.as_str())
1862                    .expect("failed to parse DD-API-KEY header"),
1863            );
1864        };
1865        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1866            headers.insert(
1867                "DD-APPLICATION-KEY",
1868                HeaderValue::from_str(local_key.key.as_str())
1869                    .expect("failed to parse DD-APPLICATION-KEY header"),
1870            );
1871        };
1872
1873        // build body parameters
1874        let output = Vec::new();
1875        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1876        if body.serialize(&mut ser).is_ok() {
1877            if let Some(content_encoding) = headers.get("Content-Encoding") {
1878                match content_encoding.to_str().unwrap_or_default() {
1879                    "gzip" => {
1880                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1881                        let _ = enc.write_all(ser.into_inner().as_slice());
1882                        match enc.finish() {
1883                            Ok(buf) => {
1884                                local_req_builder = local_req_builder.body(buf);
1885                            }
1886                            Err(e) => return Err(datadog::Error::Io(e)),
1887                        }
1888                    }
1889                    "deflate" => {
1890                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1891                        let _ = enc.write_all(ser.into_inner().as_slice());
1892                        match enc.finish() {
1893                            Ok(buf) => {
1894                                local_req_builder = local_req_builder.body(buf);
1895                            }
1896                            Err(e) => return Err(datadog::Error::Io(e)),
1897                        }
1898                    }
1899                    "zstd1" => {
1900                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1901                        let _ = enc.write_all(ser.into_inner().as_slice());
1902                        match enc.finish() {
1903                            Ok(buf) => {
1904                                local_req_builder = local_req_builder.body(buf);
1905                            }
1906                            Err(e) => return Err(datadog::Error::Io(e)),
1907                        }
1908                    }
1909                    _ => {
1910                        local_req_builder = local_req_builder.body(ser.into_inner());
1911                    }
1912                }
1913            } else {
1914                local_req_builder = local_req_builder.body(ser.into_inner());
1915            }
1916        }
1917
1918        local_req_builder = local_req_builder.headers(headers);
1919        let local_req = local_req_builder.build()?;
1920        log::debug!("request content: {:?}", local_req.body());
1921        let local_resp = local_client.execute(local_req).await?;
1922
1923        let local_status = local_resp.status();
1924        let local_content = local_resp.text().await?;
1925        log::debug!("response content: {}", local_content);
1926
1927        if !local_status.is_client_error() && !local_status.is_server_error() {
1928            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
1929                Ok(e) => {
1930                    return Ok(datadog::ResponseContent {
1931                        status: local_status,
1932                        content: local_content,
1933                        entity: Some(e),
1934                    })
1935                }
1936                Err(e) => return Err(datadog::Error::Serde(e)),
1937            };
1938        } else {
1939            let local_entity: Option<UnarchiveCaseError> =
1940                serde_json::from_str(&local_content).ok();
1941            let local_error = datadog::ResponseContent {
1942                status: local_status,
1943                content: local_content,
1944                entity: local_entity,
1945            };
1946            Err(datadog::Error::ResponseError(local_error))
1947        }
1948    }
1949
1950    /// Unassign case
1951    pub async fn unassign_case(
1952        &self,
1953        case_id: String,
1954        body: crate::datadogV2::model::CaseEmptyRequest,
1955    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UnassignCaseError>> {
1956        match self.unassign_case_with_http_info(case_id, body).await {
1957            Ok(response_content) => {
1958                if let Some(e) = response_content.entity {
1959                    Ok(e)
1960                } else {
1961                    Err(datadog::Error::Serde(serde::de::Error::custom(
1962                        "response content was None",
1963                    )))
1964                }
1965            }
1966            Err(err) => Err(err),
1967        }
1968    }
1969
1970    /// Unassign case
1971    pub async fn unassign_case_with_http_info(
1972        &self,
1973        case_id: String,
1974        body: crate::datadogV2::model::CaseEmptyRequest,
1975    ) -> Result<
1976        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
1977        datadog::Error<UnassignCaseError>,
1978    > {
1979        let local_configuration = &self.config;
1980        let operation_id = "v2.unassign_case";
1981
1982        let local_client = &self.client;
1983
1984        let local_uri_str = format!(
1985            "{}/api/v2/cases/{case_id}/unassign",
1986            local_configuration.get_operation_host(operation_id),
1987            case_id = datadog::urlencode(case_id)
1988        );
1989        let mut local_req_builder =
1990            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1991
1992        // build headers
1993        let mut headers = HeaderMap::new();
1994        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1995        headers.insert("Accept", HeaderValue::from_static("application/json"));
1996
1997        // build user agent
1998        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1999            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2000            Err(e) => {
2001                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2002                headers.insert(
2003                    reqwest::header::USER_AGENT,
2004                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2005                )
2006            }
2007        };
2008
2009        // build auth
2010        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2011            headers.insert(
2012                "DD-API-KEY",
2013                HeaderValue::from_str(local_key.key.as_str())
2014                    .expect("failed to parse DD-API-KEY header"),
2015            );
2016        };
2017        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2018            headers.insert(
2019                "DD-APPLICATION-KEY",
2020                HeaderValue::from_str(local_key.key.as_str())
2021                    .expect("failed to parse DD-APPLICATION-KEY header"),
2022            );
2023        };
2024
2025        // build body parameters
2026        let output = Vec::new();
2027        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2028        if body.serialize(&mut ser).is_ok() {
2029            if let Some(content_encoding) = headers.get("Content-Encoding") {
2030                match content_encoding.to_str().unwrap_or_default() {
2031                    "gzip" => {
2032                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2033                        let _ = enc.write_all(ser.into_inner().as_slice());
2034                        match enc.finish() {
2035                            Ok(buf) => {
2036                                local_req_builder = local_req_builder.body(buf);
2037                            }
2038                            Err(e) => return Err(datadog::Error::Io(e)),
2039                        }
2040                    }
2041                    "deflate" => {
2042                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2043                        let _ = enc.write_all(ser.into_inner().as_slice());
2044                        match enc.finish() {
2045                            Ok(buf) => {
2046                                local_req_builder = local_req_builder.body(buf);
2047                            }
2048                            Err(e) => return Err(datadog::Error::Io(e)),
2049                        }
2050                    }
2051                    "zstd1" => {
2052                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2053                        let _ = enc.write_all(ser.into_inner().as_slice());
2054                        match enc.finish() {
2055                            Ok(buf) => {
2056                                local_req_builder = local_req_builder.body(buf);
2057                            }
2058                            Err(e) => return Err(datadog::Error::Io(e)),
2059                        }
2060                    }
2061                    _ => {
2062                        local_req_builder = local_req_builder.body(ser.into_inner());
2063                    }
2064                }
2065            } else {
2066                local_req_builder = local_req_builder.body(ser.into_inner());
2067            }
2068        }
2069
2070        local_req_builder = local_req_builder.headers(headers);
2071        let local_req = local_req_builder.build()?;
2072        log::debug!("request content: {:?}", local_req.body());
2073        let local_resp = local_client.execute(local_req).await?;
2074
2075        let local_status = local_resp.status();
2076        let local_content = local_resp.text().await?;
2077        log::debug!("response content: {}", local_content);
2078
2079        if !local_status.is_client_error() && !local_status.is_server_error() {
2080            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
2081                Ok(e) => {
2082                    return Ok(datadog::ResponseContent {
2083                        status: local_status,
2084                        content: local_content,
2085                        entity: Some(e),
2086                    })
2087                }
2088                Err(e) => return Err(datadog::Error::Serde(e)),
2089            };
2090        } else {
2091            let local_entity: Option<UnassignCaseError> = serde_json::from_str(&local_content).ok();
2092            let local_error = datadog::ResponseContent {
2093                status: local_status,
2094                content: local_content,
2095                entity: local_entity,
2096            };
2097            Err(datadog::Error::ResponseError(local_error))
2098        }
2099    }
2100
2101    /// Update case attributes
2102    pub async fn update_attributes(
2103        &self,
2104        case_id: String,
2105        body: crate::datadogV2::model::CaseUpdateAttributesRequest,
2106    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdateAttributesError>> {
2107        match self.update_attributes_with_http_info(case_id, body).await {
2108            Ok(response_content) => {
2109                if let Some(e) = response_content.entity {
2110                    Ok(e)
2111                } else {
2112                    Err(datadog::Error::Serde(serde::de::Error::custom(
2113                        "response content was None",
2114                    )))
2115                }
2116            }
2117            Err(err) => Err(err),
2118        }
2119    }
2120
2121    /// Update case attributes
2122    pub async fn update_attributes_with_http_info(
2123        &self,
2124        case_id: String,
2125        body: crate::datadogV2::model::CaseUpdateAttributesRequest,
2126    ) -> Result<
2127        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
2128        datadog::Error<UpdateAttributesError>,
2129    > {
2130        let local_configuration = &self.config;
2131        let operation_id = "v2.update_attributes";
2132
2133        let local_client = &self.client;
2134
2135        let local_uri_str = format!(
2136            "{}/api/v2/cases/{case_id}/attributes",
2137            local_configuration.get_operation_host(operation_id),
2138            case_id = datadog::urlencode(case_id)
2139        );
2140        let mut local_req_builder =
2141            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2142
2143        // build headers
2144        let mut headers = HeaderMap::new();
2145        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2146        headers.insert("Accept", HeaderValue::from_static("application/json"));
2147
2148        // build user agent
2149        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2150            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2151            Err(e) => {
2152                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2153                headers.insert(
2154                    reqwest::header::USER_AGENT,
2155                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2156                )
2157            }
2158        };
2159
2160        // build auth
2161        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2162            headers.insert(
2163                "DD-API-KEY",
2164                HeaderValue::from_str(local_key.key.as_str())
2165                    .expect("failed to parse DD-API-KEY header"),
2166            );
2167        };
2168        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2169            headers.insert(
2170                "DD-APPLICATION-KEY",
2171                HeaderValue::from_str(local_key.key.as_str())
2172                    .expect("failed to parse DD-APPLICATION-KEY header"),
2173            );
2174        };
2175
2176        // build body parameters
2177        let output = Vec::new();
2178        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2179        if body.serialize(&mut ser).is_ok() {
2180            if let Some(content_encoding) = headers.get("Content-Encoding") {
2181                match content_encoding.to_str().unwrap_or_default() {
2182                    "gzip" => {
2183                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2184                        let _ = enc.write_all(ser.into_inner().as_slice());
2185                        match enc.finish() {
2186                            Ok(buf) => {
2187                                local_req_builder = local_req_builder.body(buf);
2188                            }
2189                            Err(e) => return Err(datadog::Error::Io(e)),
2190                        }
2191                    }
2192                    "deflate" => {
2193                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2194                        let _ = enc.write_all(ser.into_inner().as_slice());
2195                        match enc.finish() {
2196                            Ok(buf) => {
2197                                local_req_builder = local_req_builder.body(buf);
2198                            }
2199                            Err(e) => return Err(datadog::Error::Io(e)),
2200                        }
2201                    }
2202                    "zstd1" => {
2203                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2204                        let _ = enc.write_all(ser.into_inner().as_slice());
2205                        match enc.finish() {
2206                            Ok(buf) => {
2207                                local_req_builder = local_req_builder.body(buf);
2208                            }
2209                            Err(e) => return Err(datadog::Error::Io(e)),
2210                        }
2211                    }
2212                    _ => {
2213                        local_req_builder = local_req_builder.body(ser.into_inner());
2214                    }
2215                }
2216            } else {
2217                local_req_builder = local_req_builder.body(ser.into_inner());
2218            }
2219        }
2220
2221        local_req_builder = local_req_builder.headers(headers);
2222        let local_req = local_req_builder.build()?;
2223        log::debug!("request content: {:?}", local_req.body());
2224        let local_resp = local_client.execute(local_req).await?;
2225
2226        let local_status = local_resp.status();
2227        let local_content = local_resp.text().await?;
2228        log::debug!("response content: {}", local_content);
2229
2230        if !local_status.is_client_error() && !local_status.is_server_error() {
2231            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
2232                Ok(e) => {
2233                    return Ok(datadog::ResponseContent {
2234                        status: local_status,
2235                        content: local_content,
2236                        entity: Some(e),
2237                    })
2238                }
2239                Err(e) => return Err(datadog::Error::Serde(e)),
2240            };
2241        } else {
2242            let local_entity: Option<UpdateAttributesError> =
2243                serde_json::from_str(&local_content).ok();
2244            let local_error = datadog::ResponseContent {
2245                status: local_status,
2246                content: local_content,
2247                entity: local_entity,
2248            };
2249            Err(datadog::Error::ResponseError(local_error))
2250        }
2251    }
2252
2253    /// Update case custom attribute
2254    pub async fn update_case_custom_attribute(
2255        &self,
2256        case_id: String,
2257        custom_attribute_key: String,
2258        body: crate::datadogV2::model::CaseUpdateCustomAttributeRequest,
2259    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdateCaseCustomAttributeError>>
2260    {
2261        match self
2262            .update_case_custom_attribute_with_http_info(case_id, custom_attribute_key, body)
2263            .await
2264        {
2265            Ok(response_content) => {
2266                if let Some(e) = response_content.entity {
2267                    Ok(e)
2268                } else {
2269                    Err(datadog::Error::Serde(serde::de::Error::custom(
2270                        "response content was None",
2271                    )))
2272                }
2273            }
2274            Err(err) => Err(err),
2275        }
2276    }
2277
2278    /// Update case custom attribute
2279    pub async fn update_case_custom_attribute_with_http_info(
2280        &self,
2281        case_id: String,
2282        custom_attribute_key: String,
2283        body: crate::datadogV2::model::CaseUpdateCustomAttributeRequest,
2284    ) -> Result<
2285        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
2286        datadog::Error<UpdateCaseCustomAttributeError>,
2287    > {
2288        let local_configuration = &self.config;
2289        let operation_id = "v2.update_case_custom_attribute";
2290
2291        let local_client = &self.client;
2292
2293        let local_uri_str = format!(
2294            "{}/api/v2/cases/{case_id}/custom_attributes/{custom_attribute_key}",
2295            local_configuration.get_operation_host(operation_id),
2296            case_id = datadog::urlencode(case_id),
2297            custom_attribute_key = datadog::urlencode(custom_attribute_key)
2298        );
2299        let mut local_req_builder =
2300            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2301
2302        // build headers
2303        let mut headers = HeaderMap::new();
2304        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2305        headers.insert("Accept", HeaderValue::from_static("application/json"));
2306
2307        // build user agent
2308        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2309            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2310            Err(e) => {
2311                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2312                headers.insert(
2313                    reqwest::header::USER_AGENT,
2314                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2315                )
2316            }
2317        };
2318
2319        // build auth
2320        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2321            headers.insert(
2322                "DD-API-KEY",
2323                HeaderValue::from_str(local_key.key.as_str())
2324                    .expect("failed to parse DD-API-KEY header"),
2325            );
2326        };
2327        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2328            headers.insert(
2329                "DD-APPLICATION-KEY",
2330                HeaderValue::from_str(local_key.key.as_str())
2331                    .expect("failed to parse DD-APPLICATION-KEY header"),
2332            );
2333        };
2334
2335        // build body parameters
2336        let output = Vec::new();
2337        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2338        if body.serialize(&mut ser).is_ok() {
2339            if let Some(content_encoding) = headers.get("Content-Encoding") {
2340                match content_encoding.to_str().unwrap_or_default() {
2341                    "gzip" => {
2342                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2343                        let _ = enc.write_all(ser.into_inner().as_slice());
2344                        match enc.finish() {
2345                            Ok(buf) => {
2346                                local_req_builder = local_req_builder.body(buf);
2347                            }
2348                            Err(e) => return Err(datadog::Error::Io(e)),
2349                        }
2350                    }
2351                    "deflate" => {
2352                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2353                        let _ = enc.write_all(ser.into_inner().as_slice());
2354                        match enc.finish() {
2355                            Ok(buf) => {
2356                                local_req_builder = local_req_builder.body(buf);
2357                            }
2358                            Err(e) => return Err(datadog::Error::Io(e)),
2359                        }
2360                    }
2361                    "zstd1" => {
2362                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2363                        let _ = enc.write_all(ser.into_inner().as_slice());
2364                        match enc.finish() {
2365                            Ok(buf) => {
2366                                local_req_builder = local_req_builder.body(buf);
2367                            }
2368                            Err(e) => return Err(datadog::Error::Io(e)),
2369                        }
2370                    }
2371                    _ => {
2372                        local_req_builder = local_req_builder.body(ser.into_inner());
2373                    }
2374                }
2375            } else {
2376                local_req_builder = local_req_builder.body(ser.into_inner());
2377            }
2378        }
2379
2380        local_req_builder = local_req_builder.headers(headers);
2381        let local_req = local_req_builder.build()?;
2382        log::debug!("request content: {:?}", local_req.body());
2383        let local_resp = local_client.execute(local_req).await?;
2384
2385        let local_status = local_resp.status();
2386        let local_content = local_resp.text().await?;
2387        log::debug!("response content: {}", local_content);
2388
2389        if !local_status.is_client_error() && !local_status.is_server_error() {
2390            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
2391                Ok(e) => {
2392                    return Ok(datadog::ResponseContent {
2393                        status: local_status,
2394                        content: local_content,
2395                        entity: Some(e),
2396                    })
2397                }
2398                Err(e) => return Err(datadog::Error::Serde(e)),
2399            };
2400        } else {
2401            let local_entity: Option<UpdateCaseCustomAttributeError> =
2402                serde_json::from_str(&local_content).ok();
2403            let local_error = datadog::ResponseContent {
2404                status: local_status,
2405                content: local_content,
2406                entity: local_entity,
2407            };
2408            Err(datadog::Error::ResponseError(local_error))
2409        }
2410    }
2411
2412    /// Update case description
2413    pub async fn update_case_description(
2414        &self,
2415        case_id: String,
2416        body: crate::datadogV2::model::CaseUpdateDescriptionRequest,
2417    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdateCaseDescriptionError>>
2418    {
2419        match self
2420            .update_case_description_with_http_info(case_id, body)
2421            .await
2422        {
2423            Ok(response_content) => {
2424                if let Some(e) = response_content.entity {
2425                    Ok(e)
2426                } else {
2427                    Err(datadog::Error::Serde(serde::de::Error::custom(
2428                        "response content was None",
2429                    )))
2430                }
2431            }
2432            Err(err) => Err(err),
2433        }
2434    }
2435
2436    /// Update case description
2437    pub async fn update_case_description_with_http_info(
2438        &self,
2439        case_id: String,
2440        body: crate::datadogV2::model::CaseUpdateDescriptionRequest,
2441    ) -> Result<
2442        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
2443        datadog::Error<UpdateCaseDescriptionError>,
2444    > {
2445        let local_configuration = &self.config;
2446        let operation_id = "v2.update_case_description";
2447
2448        let local_client = &self.client;
2449
2450        let local_uri_str = format!(
2451            "{}/api/v2/cases/{case_id}/description",
2452            local_configuration.get_operation_host(operation_id),
2453            case_id = datadog::urlencode(case_id)
2454        );
2455        let mut local_req_builder =
2456            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2457
2458        // build headers
2459        let mut headers = HeaderMap::new();
2460        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2461        headers.insert("Accept", HeaderValue::from_static("application/json"));
2462
2463        // build user agent
2464        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2465            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2466            Err(e) => {
2467                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2468                headers.insert(
2469                    reqwest::header::USER_AGENT,
2470                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2471                )
2472            }
2473        };
2474
2475        // build auth
2476        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2477            headers.insert(
2478                "DD-API-KEY",
2479                HeaderValue::from_str(local_key.key.as_str())
2480                    .expect("failed to parse DD-API-KEY header"),
2481            );
2482        };
2483        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2484            headers.insert(
2485                "DD-APPLICATION-KEY",
2486                HeaderValue::from_str(local_key.key.as_str())
2487                    .expect("failed to parse DD-APPLICATION-KEY header"),
2488            );
2489        };
2490
2491        // build body parameters
2492        let output = Vec::new();
2493        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2494        if body.serialize(&mut ser).is_ok() {
2495            if let Some(content_encoding) = headers.get("Content-Encoding") {
2496                match content_encoding.to_str().unwrap_or_default() {
2497                    "gzip" => {
2498                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2499                        let _ = enc.write_all(ser.into_inner().as_slice());
2500                        match enc.finish() {
2501                            Ok(buf) => {
2502                                local_req_builder = local_req_builder.body(buf);
2503                            }
2504                            Err(e) => return Err(datadog::Error::Io(e)),
2505                        }
2506                    }
2507                    "deflate" => {
2508                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2509                        let _ = enc.write_all(ser.into_inner().as_slice());
2510                        match enc.finish() {
2511                            Ok(buf) => {
2512                                local_req_builder = local_req_builder.body(buf);
2513                            }
2514                            Err(e) => return Err(datadog::Error::Io(e)),
2515                        }
2516                    }
2517                    "zstd1" => {
2518                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2519                        let _ = enc.write_all(ser.into_inner().as_slice());
2520                        match enc.finish() {
2521                            Ok(buf) => {
2522                                local_req_builder = local_req_builder.body(buf);
2523                            }
2524                            Err(e) => return Err(datadog::Error::Io(e)),
2525                        }
2526                    }
2527                    _ => {
2528                        local_req_builder = local_req_builder.body(ser.into_inner());
2529                    }
2530                }
2531            } else {
2532                local_req_builder = local_req_builder.body(ser.into_inner());
2533            }
2534        }
2535
2536        local_req_builder = local_req_builder.headers(headers);
2537        let local_req = local_req_builder.build()?;
2538        log::debug!("request content: {:?}", local_req.body());
2539        let local_resp = local_client.execute(local_req).await?;
2540
2541        let local_status = local_resp.status();
2542        let local_content = local_resp.text().await?;
2543        log::debug!("response content: {}", local_content);
2544
2545        if !local_status.is_client_error() && !local_status.is_server_error() {
2546            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
2547                Ok(e) => {
2548                    return Ok(datadog::ResponseContent {
2549                        status: local_status,
2550                        content: local_content,
2551                        entity: Some(e),
2552                    })
2553                }
2554                Err(e) => return Err(datadog::Error::Serde(e)),
2555            };
2556        } else {
2557            let local_entity: Option<UpdateCaseDescriptionError> =
2558                serde_json::from_str(&local_content).ok();
2559            let local_error = datadog::ResponseContent {
2560                status: local_status,
2561                content: local_content,
2562                entity: local_entity,
2563            };
2564            Err(datadog::Error::ResponseError(local_error))
2565        }
2566    }
2567
2568    /// Update case title
2569    pub async fn update_case_title(
2570        &self,
2571        case_id: String,
2572        body: crate::datadogV2::model::CaseUpdateTitleRequest,
2573    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdateCaseTitleError>> {
2574        match self.update_case_title_with_http_info(case_id, body).await {
2575            Ok(response_content) => {
2576                if let Some(e) = response_content.entity {
2577                    Ok(e)
2578                } else {
2579                    Err(datadog::Error::Serde(serde::de::Error::custom(
2580                        "response content was None",
2581                    )))
2582                }
2583            }
2584            Err(err) => Err(err),
2585        }
2586    }
2587
2588    /// Update case title
2589    pub async fn update_case_title_with_http_info(
2590        &self,
2591        case_id: String,
2592        body: crate::datadogV2::model::CaseUpdateTitleRequest,
2593    ) -> Result<
2594        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
2595        datadog::Error<UpdateCaseTitleError>,
2596    > {
2597        let local_configuration = &self.config;
2598        let operation_id = "v2.update_case_title";
2599
2600        let local_client = &self.client;
2601
2602        let local_uri_str = format!(
2603            "{}/api/v2/cases/{case_id}/title",
2604            local_configuration.get_operation_host(operation_id),
2605            case_id = datadog::urlencode(case_id)
2606        );
2607        let mut local_req_builder =
2608            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2609
2610        // build headers
2611        let mut headers = HeaderMap::new();
2612        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2613        headers.insert("Accept", HeaderValue::from_static("application/json"));
2614
2615        // build user agent
2616        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2617            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2618            Err(e) => {
2619                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2620                headers.insert(
2621                    reqwest::header::USER_AGENT,
2622                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2623                )
2624            }
2625        };
2626
2627        // build auth
2628        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2629            headers.insert(
2630                "DD-API-KEY",
2631                HeaderValue::from_str(local_key.key.as_str())
2632                    .expect("failed to parse DD-API-KEY header"),
2633            );
2634        };
2635        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2636            headers.insert(
2637                "DD-APPLICATION-KEY",
2638                HeaderValue::from_str(local_key.key.as_str())
2639                    .expect("failed to parse DD-APPLICATION-KEY header"),
2640            );
2641        };
2642
2643        // build body parameters
2644        let output = Vec::new();
2645        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2646        if body.serialize(&mut ser).is_ok() {
2647            if let Some(content_encoding) = headers.get("Content-Encoding") {
2648                match content_encoding.to_str().unwrap_or_default() {
2649                    "gzip" => {
2650                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2651                        let _ = enc.write_all(ser.into_inner().as_slice());
2652                        match enc.finish() {
2653                            Ok(buf) => {
2654                                local_req_builder = local_req_builder.body(buf);
2655                            }
2656                            Err(e) => return Err(datadog::Error::Io(e)),
2657                        }
2658                    }
2659                    "deflate" => {
2660                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2661                        let _ = enc.write_all(ser.into_inner().as_slice());
2662                        match enc.finish() {
2663                            Ok(buf) => {
2664                                local_req_builder = local_req_builder.body(buf);
2665                            }
2666                            Err(e) => return Err(datadog::Error::Io(e)),
2667                        }
2668                    }
2669                    "zstd1" => {
2670                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2671                        let _ = enc.write_all(ser.into_inner().as_slice());
2672                        match enc.finish() {
2673                            Ok(buf) => {
2674                                local_req_builder = local_req_builder.body(buf);
2675                            }
2676                            Err(e) => return Err(datadog::Error::Io(e)),
2677                        }
2678                    }
2679                    _ => {
2680                        local_req_builder = local_req_builder.body(ser.into_inner());
2681                    }
2682                }
2683            } else {
2684                local_req_builder = local_req_builder.body(ser.into_inner());
2685            }
2686        }
2687
2688        local_req_builder = local_req_builder.headers(headers);
2689        let local_req = local_req_builder.build()?;
2690        log::debug!("request content: {:?}", local_req.body());
2691        let local_resp = local_client.execute(local_req).await?;
2692
2693        let local_status = local_resp.status();
2694        let local_content = local_resp.text().await?;
2695        log::debug!("response content: {}", local_content);
2696
2697        if !local_status.is_client_error() && !local_status.is_server_error() {
2698            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
2699                Ok(e) => {
2700                    return Ok(datadog::ResponseContent {
2701                        status: local_status,
2702                        content: local_content,
2703                        entity: Some(e),
2704                    })
2705                }
2706                Err(e) => return Err(datadog::Error::Serde(e)),
2707            };
2708        } else {
2709            let local_entity: Option<UpdateCaseTitleError> =
2710                serde_json::from_str(&local_content).ok();
2711            let local_error = datadog::ResponseContent {
2712                status: local_status,
2713                content: local_content,
2714                entity: local_entity,
2715            };
2716            Err(datadog::Error::ResponseError(local_error))
2717        }
2718    }
2719
2720    /// Update case priority
2721    pub async fn update_priority(
2722        &self,
2723        case_id: String,
2724        body: crate::datadogV2::model::CaseUpdatePriorityRequest,
2725    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdatePriorityError>> {
2726        match self.update_priority_with_http_info(case_id, body).await {
2727            Ok(response_content) => {
2728                if let Some(e) = response_content.entity {
2729                    Ok(e)
2730                } else {
2731                    Err(datadog::Error::Serde(serde::de::Error::custom(
2732                        "response content was None",
2733                    )))
2734                }
2735            }
2736            Err(err) => Err(err),
2737        }
2738    }
2739
2740    /// Update case priority
2741    pub async fn update_priority_with_http_info(
2742        &self,
2743        case_id: String,
2744        body: crate::datadogV2::model::CaseUpdatePriorityRequest,
2745    ) -> Result<
2746        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
2747        datadog::Error<UpdatePriorityError>,
2748    > {
2749        let local_configuration = &self.config;
2750        let operation_id = "v2.update_priority";
2751
2752        let local_client = &self.client;
2753
2754        let local_uri_str = format!(
2755            "{}/api/v2/cases/{case_id}/priority",
2756            local_configuration.get_operation_host(operation_id),
2757            case_id = datadog::urlencode(case_id)
2758        );
2759        let mut local_req_builder =
2760            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2761
2762        // build headers
2763        let mut headers = HeaderMap::new();
2764        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2765        headers.insert("Accept", HeaderValue::from_static("application/json"));
2766
2767        // build user agent
2768        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2769            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2770            Err(e) => {
2771                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2772                headers.insert(
2773                    reqwest::header::USER_AGENT,
2774                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2775                )
2776            }
2777        };
2778
2779        // build auth
2780        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2781            headers.insert(
2782                "DD-API-KEY",
2783                HeaderValue::from_str(local_key.key.as_str())
2784                    .expect("failed to parse DD-API-KEY header"),
2785            );
2786        };
2787        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2788            headers.insert(
2789                "DD-APPLICATION-KEY",
2790                HeaderValue::from_str(local_key.key.as_str())
2791                    .expect("failed to parse DD-APPLICATION-KEY header"),
2792            );
2793        };
2794
2795        // build body parameters
2796        let output = Vec::new();
2797        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2798        if body.serialize(&mut ser).is_ok() {
2799            if let Some(content_encoding) = headers.get("Content-Encoding") {
2800                match content_encoding.to_str().unwrap_or_default() {
2801                    "gzip" => {
2802                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2803                        let _ = enc.write_all(ser.into_inner().as_slice());
2804                        match enc.finish() {
2805                            Ok(buf) => {
2806                                local_req_builder = local_req_builder.body(buf);
2807                            }
2808                            Err(e) => return Err(datadog::Error::Io(e)),
2809                        }
2810                    }
2811                    "deflate" => {
2812                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2813                        let _ = enc.write_all(ser.into_inner().as_slice());
2814                        match enc.finish() {
2815                            Ok(buf) => {
2816                                local_req_builder = local_req_builder.body(buf);
2817                            }
2818                            Err(e) => return Err(datadog::Error::Io(e)),
2819                        }
2820                    }
2821                    "zstd1" => {
2822                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2823                        let _ = enc.write_all(ser.into_inner().as_slice());
2824                        match enc.finish() {
2825                            Ok(buf) => {
2826                                local_req_builder = local_req_builder.body(buf);
2827                            }
2828                            Err(e) => return Err(datadog::Error::Io(e)),
2829                        }
2830                    }
2831                    _ => {
2832                        local_req_builder = local_req_builder.body(ser.into_inner());
2833                    }
2834                }
2835            } else {
2836                local_req_builder = local_req_builder.body(ser.into_inner());
2837            }
2838        }
2839
2840        local_req_builder = local_req_builder.headers(headers);
2841        let local_req = local_req_builder.build()?;
2842        log::debug!("request content: {:?}", local_req.body());
2843        let local_resp = local_client.execute(local_req).await?;
2844
2845        let local_status = local_resp.status();
2846        let local_content = local_resp.text().await?;
2847        log::debug!("response content: {}", local_content);
2848
2849        if !local_status.is_client_error() && !local_status.is_server_error() {
2850            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
2851                Ok(e) => {
2852                    return Ok(datadog::ResponseContent {
2853                        status: local_status,
2854                        content: local_content,
2855                        entity: Some(e),
2856                    })
2857                }
2858                Err(e) => return Err(datadog::Error::Serde(e)),
2859            };
2860        } else {
2861            let local_entity: Option<UpdatePriorityError> =
2862                serde_json::from_str(&local_content).ok();
2863            let local_error = datadog::ResponseContent {
2864                status: local_status,
2865                content: local_content,
2866                entity: local_entity,
2867            };
2868            Err(datadog::Error::ResponseError(local_error))
2869        }
2870    }
2871
2872    /// Update case status
2873    pub async fn update_status(
2874        &self,
2875        case_id: String,
2876        body: crate::datadogV2::model::CaseUpdateStatusRequest,
2877    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdateStatusError>> {
2878        match self.update_status_with_http_info(case_id, body).await {
2879            Ok(response_content) => {
2880                if let Some(e) = response_content.entity {
2881                    Ok(e)
2882                } else {
2883                    Err(datadog::Error::Serde(serde::de::Error::custom(
2884                        "response content was None",
2885                    )))
2886                }
2887            }
2888            Err(err) => Err(err),
2889        }
2890    }
2891
2892    /// Update case status
2893    pub async fn update_status_with_http_info(
2894        &self,
2895        case_id: String,
2896        body: crate::datadogV2::model::CaseUpdateStatusRequest,
2897    ) -> Result<
2898        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
2899        datadog::Error<UpdateStatusError>,
2900    > {
2901        let local_configuration = &self.config;
2902        let operation_id = "v2.update_status";
2903
2904        let local_client = &self.client;
2905
2906        let local_uri_str = format!(
2907            "{}/api/v2/cases/{case_id}/status",
2908            local_configuration.get_operation_host(operation_id),
2909            case_id = datadog::urlencode(case_id)
2910        );
2911        let mut local_req_builder =
2912            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2913
2914        // build headers
2915        let mut headers = HeaderMap::new();
2916        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2917        headers.insert("Accept", HeaderValue::from_static("application/json"));
2918
2919        // build user agent
2920        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2921            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2922            Err(e) => {
2923                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2924                headers.insert(
2925                    reqwest::header::USER_AGENT,
2926                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2927                )
2928            }
2929        };
2930
2931        // build auth
2932        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2933            headers.insert(
2934                "DD-API-KEY",
2935                HeaderValue::from_str(local_key.key.as_str())
2936                    .expect("failed to parse DD-API-KEY header"),
2937            );
2938        };
2939        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2940            headers.insert(
2941                "DD-APPLICATION-KEY",
2942                HeaderValue::from_str(local_key.key.as_str())
2943                    .expect("failed to parse DD-APPLICATION-KEY header"),
2944            );
2945        };
2946
2947        // build body parameters
2948        let output = Vec::new();
2949        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2950        if body.serialize(&mut ser).is_ok() {
2951            if let Some(content_encoding) = headers.get("Content-Encoding") {
2952                match content_encoding.to_str().unwrap_or_default() {
2953                    "gzip" => {
2954                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2955                        let _ = enc.write_all(ser.into_inner().as_slice());
2956                        match enc.finish() {
2957                            Ok(buf) => {
2958                                local_req_builder = local_req_builder.body(buf);
2959                            }
2960                            Err(e) => return Err(datadog::Error::Io(e)),
2961                        }
2962                    }
2963                    "deflate" => {
2964                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2965                        let _ = enc.write_all(ser.into_inner().as_slice());
2966                        match enc.finish() {
2967                            Ok(buf) => {
2968                                local_req_builder = local_req_builder.body(buf);
2969                            }
2970                            Err(e) => return Err(datadog::Error::Io(e)),
2971                        }
2972                    }
2973                    "zstd1" => {
2974                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2975                        let _ = enc.write_all(ser.into_inner().as_slice());
2976                        match enc.finish() {
2977                            Ok(buf) => {
2978                                local_req_builder = local_req_builder.body(buf);
2979                            }
2980                            Err(e) => return Err(datadog::Error::Io(e)),
2981                        }
2982                    }
2983                    _ => {
2984                        local_req_builder = local_req_builder.body(ser.into_inner());
2985                    }
2986                }
2987            } else {
2988                local_req_builder = local_req_builder.body(ser.into_inner());
2989            }
2990        }
2991
2992        local_req_builder = local_req_builder.headers(headers);
2993        let local_req = local_req_builder.build()?;
2994        log::debug!("request content: {:?}", local_req.body());
2995        let local_resp = local_client.execute(local_req).await?;
2996
2997        let local_status = local_resp.status();
2998        let local_content = local_resp.text().await?;
2999        log::debug!("response content: {}", local_content);
3000
3001        if !local_status.is_client_error() && !local_status.is_server_error() {
3002            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
3003                Ok(e) => {
3004                    return Ok(datadog::ResponseContent {
3005                        status: local_status,
3006                        content: local_content,
3007                        entity: Some(e),
3008                    })
3009                }
3010                Err(e) => return Err(datadog::Error::Serde(e)),
3011            };
3012        } else {
3013            let local_entity: Option<UpdateStatusError> = serde_json::from_str(&local_content).ok();
3014            let local_error = datadog::ResponseContent {
3015                status: local_status,
3016                content: local_content,
3017                entity: local_entity,
3018            };
3019            Err(datadog::Error::ResponseError(local_error))
3020        }
3021    }
3022}