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/// CreateCaseError is a struct for typed errors of method [`CaseManagementAPI::create_case`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum CreateCaseError {
79    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
80    UnknownValue(serde_json::Value),
81}
82
83/// CreateProjectError is a struct for typed errors of method [`CaseManagementAPI::create_project`]
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum CreateProjectError {
87    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
88    UnknownValue(serde_json::Value),
89}
90
91/// DeleteProjectError is a struct for typed errors of method [`CaseManagementAPI::delete_project`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum DeleteProjectError {
95    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
96    UnknownValue(serde_json::Value),
97}
98
99/// GetCaseError is a struct for typed errors of method [`CaseManagementAPI::get_case`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum GetCaseError {
103    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
104    UnknownValue(serde_json::Value),
105}
106
107/// GetProjectError is a struct for typed errors of method [`CaseManagementAPI::get_project`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetProjectError {
111    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
112    UnknownValue(serde_json::Value),
113}
114
115/// GetProjectsError is a struct for typed errors of method [`CaseManagementAPI::get_projects`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum GetProjectsError {
119    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
120    UnknownValue(serde_json::Value),
121}
122
123/// SearchCasesError is a struct for typed errors of method [`CaseManagementAPI::search_cases`]
124#[derive(Debug, Clone, Serialize, Deserialize)]
125#[serde(untagged)]
126pub enum SearchCasesError {
127    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
128    UnknownValue(serde_json::Value),
129}
130
131/// UnarchiveCaseError is a struct for typed errors of method [`CaseManagementAPI::unarchive_case`]
132#[derive(Debug, Clone, Serialize, Deserialize)]
133#[serde(untagged)]
134pub enum UnarchiveCaseError {
135    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
136    UnknownValue(serde_json::Value),
137}
138
139/// UnassignCaseError is a struct for typed errors of method [`CaseManagementAPI::unassign_case`]
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(untagged)]
142pub enum UnassignCaseError {
143    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
144    UnknownValue(serde_json::Value),
145}
146
147/// UpdateAttributesError is a struct for typed errors of method [`CaseManagementAPI::update_attributes`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum UpdateAttributesError {
151    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
152    UnknownValue(serde_json::Value),
153}
154
155/// UpdatePriorityError is a struct for typed errors of method [`CaseManagementAPI::update_priority`]
156#[derive(Debug, Clone, Serialize, Deserialize)]
157#[serde(untagged)]
158pub enum UpdatePriorityError {
159    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
160    UnknownValue(serde_json::Value),
161}
162
163/// UpdateStatusError is a struct for typed errors of method [`CaseManagementAPI::update_status`]
164#[derive(Debug, Clone, Serialize, Deserialize)]
165#[serde(untagged)]
166pub enum UpdateStatusError {
167    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
168    UnknownValue(serde_json::Value),
169}
170
171/// 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.
172#[derive(Debug, Clone)]
173pub struct CaseManagementAPI {
174    config: datadog::Configuration,
175    client: reqwest_middleware::ClientWithMiddleware,
176}
177
178impl Default for CaseManagementAPI {
179    fn default() -> Self {
180        Self::with_config(datadog::Configuration::default())
181    }
182}
183
184impl CaseManagementAPI {
185    pub fn new() -> Self {
186        Self::default()
187    }
188    pub fn with_config(config: datadog::Configuration) -> Self {
189        let mut reqwest_client_builder = reqwest::Client::builder();
190
191        if let Some(proxy_url) = &config.proxy_url {
192            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
193            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
194        }
195
196        let mut middleware_client_builder =
197            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
198
199        if config.enable_retry {
200            struct RetryableStatus;
201            impl reqwest_retry::RetryableStrategy for RetryableStatus {
202                fn handle(
203                    &self,
204                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
205                ) -> Option<reqwest_retry::Retryable> {
206                    match res {
207                        Ok(success) => reqwest_retry::default_on_request_success(success),
208                        Err(_) => None,
209                    }
210                }
211            }
212            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
213                .build_with_max_retries(config.max_retries);
214
215            let retry_middleware =
216                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
217                    backoff_policy,
218                    RetryableStatus,
219                );
220
221            middleware_client_builder = middleware_client_builder.with(retry_middleware);
222        }
223
224        let client = middleware_client_builder.build();
225
226        Self { config, client }
227    }
228
229    pub fn with_client_and_config(
230        config: datadog::Configuration,
231        client: reqwest_middleware::ClientWithMiddleware,
232    ) -> Self {
233        Self { config, client }
234    }
235
236    /// Archive case
237    pub async fn archive_case(
238        &self,
239        case_id: String,
240        body: crate::datadogV2::model::CaseEmptyRequest,
241    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<ArchiveCaseError>> {
242        match self.archive_case_with_http_info(case_id, body).await {
243            Ok(response_content) => {
244                if let Some(e) = response_content.entity {
245                    Ok(e)
246                } else {
247                    Err(datadog::Error::Serde(serde::de::Error::custom(
248                        "response content was None",
249                    )))
250                }
251            }
252            Err(err) => Err(err),
253        }
254    }
255
256    /// Archive case
257    pub async fn archive_case_with_http_info(
258        &self,
259        case_id: String,
260        body: crate::datadogV2::model::CaseEmptyRequest,
261    ) -> Result<
262        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
263        datadog::Error<ArchiveCaseError>,
264    > {
265        let local_configuration = &self.config;
266        let operation_id = "v2.archive_case";
267
268        let local_client = &self.client;
269
270        let local_uri_str = format!(
271            "{}/api/v2/cases/{case_id}/archive",
272            local_configuration.get_operation_host(operation_id),
273            case_id = datadog::urlencode(case_id)
274        );
275        let mut local_req_builder =
276            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
277
278        // build headers
279        let mut headers = HeaderMap::new();
280        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
281        headers.insert("Accept", HeaderValue::from_static("application/json"));
282
283        // build user agent
284        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
285            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
286            Err(e) => {
287                log::warn!("Failed to parse user agent header: {e}, falling back to default");
288                headers.insert(
289                    reqwest::header::USER_AGENT,
290                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
291                )
292            }
293        };
294
295        // build auth
296        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
297            headers.insert(
298                "DD-API-KEY",
299                HeaderValue::from_str(local_key.key.as_str())
300                    .expect("failed to parse DD-API-KEY header"),
301            );
302        };
303        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
304            headers.insert(
305                "DD-APPLICATION-KEY",
306                HeaderValue::from_str(local_key.key.as_str())
307                    .expect("failed to parse DD-APPLICATION-KEY header"),
308            );
309        };
310
311        // build body parameters
312        let output = Vec::new();
313        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
314        if body.serialize(&mut ser).is_ok() {
315            if let Some(content_encoding) = headers.get("Content-Encoding") {
316                match content_encoding.to_str().unwrap_or_default() {
317                    "gzip" => {
318                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
319                        let _ = enc.write_all(ser.into_inner().as_slice());
320                        match enc.finish() {
321                            Ok(buf) => {
322                                local_req_builder = local_req_builder.body(buf);
323                            }
324                            Err(e) => return Err(datadog::Error::Io(e)),
325                        }
326                    }
327                    "deflate" => {
328                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
329                        let _ = enc.write_all(ser.into_inner().as_slice());
330                        match enc.finish() {
331                            Ok(buf) => {
332                                local_req_builder = local_req_builder.body(buf);
333                            }
334                            Err(e) => return Err(datadog::Error::Io(e)),
335                        }
336                    }
337                    "zstd1" => {
338                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
339                        let _ = enc.write_all(ser.into_inner().as_slice());
340                        match enc.finish() {
341                            Ok(buf) => {
342                                local_req_builder = local_req_builder.body(buf);
343                            }
344                            Err(e) => return Err(datadog::Error::Io(e)),
345                        }
346                    }
347                    _ => {
348                        local_req_builder = local_req_builder.body(ser.into_inner());
349                    }
350                }
351            } else {
352                local_req_builder = local_req_builder.body(ser.into_inner());
353            }
354        }
355
356        local_req_builder = local_req_builder.headers(headers);
357        let local_req = local_req_builder.build()?;
358        log::debug!("request content: {:?}", local_req.body());
359        let local_resp = local_client.execute(local_req).await?;
360
361        let local_status = local_resp.status();
362        let local_content = local_resp.text().await?;
363        log::debug!("response content: {}", local_content);
364
365        if !local_status.is_client_error() && !local_status.is_server_error() {
366            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
367                Ok(e) => {
368                    return Ok(datadog::ResponseContent {
369                        status: local_status,
370                        content: local_content,
371                        entity: Some(e),
372                    })
373                }
374                Err(e) => return Err(datadog::Error::Serde(e)),
375            };
376        } else {
377            let local_entity: Option<ArchiveCaseError> = serde_json::from_str(&local_content).ok();
378            let local_error = datadog::ResponseContent {
379                status: local_status,
380                content: local_content,
381                entity: local_entity,
382            };
383            Err(datadog::Error::ResponseError(local_error))
384        }
385    }
386
387    /// Assign case to a user
388    pub async fn assign_case(
389        &self,
390        case_id: String,
391        body: crate::datadogV2::model::CaseAssignRequest,
392    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<AssignCaseError>> {
393        match self.assign_case_with_http_info(case_id, body).await {
394            Ok(response_content) => {
395                if let Some(e) = response_content.entity {
396                    Ok(e)
397                } else {
398                    Err(datadog::Error::Serde(serde::de::Error::custom(
399                        "response content was None",
400                    )))
401                }
402            }
403            Err(err) => Err(err),
404        }
405    }
406
407    /// Assign case to a user
408    pub async fn assign_case_with_http_info(
409        &self,
410        case_id: String,
411        body: crate::datadogV2::model::CaseAssignRequest,
412    ) -> Result<
413        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
414        datadog::Error<AssignCaseError>,
415    > {
416        let local_configuration = &self.config;
417        let operation_id = "v2.assign_case";
418
419        let local_client = &self.client;
420
421        let local_uri_str = format!(
422            "{}/api/v2/cases/{case_id}/assign",
423            local_configuration.get_operation_host(operation_id),
424            case_id = datadog::urlencode(case_id)
425        );
426        let mut local_req_builder =
427            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
428
429        // build headers
430        let mut headers = HeaderMap::new();
431        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
432        headers.insert("Accept", HeaderValue::from_static("application/json"));
433
434        // build user agent
435        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
436            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
437            Err(e) => {
438                log::warn!("Failed to parse user agent header: {e}, falling back to default");
439                headers.insert(
440                    reqwest::header::USER_AGENT,
441                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
442                )
443            }
444        };
445
446        // build auth
447        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
448            headers.insert(
449                "DD-API-KEY",
450                HeaderValue::from_str(local_key.key.as_str())
451                    .expect("failed to parse DD-API-KEY header"),
452            );
453        };
454        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
455            headers.insert(
456                "DD-APPLICATION-KEY",
457                HeaderValue::from_str(local_key.key.as_str())
458                    .expect("failed to parse DD-APPLICATION-KEY header"),
459            );
460        };
461
462        // build body parameters
463        let output = Vec::new();
464        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
465        if body.serialize(&mut ser).is_ok() {
466            if let Some(content_encoding) = headers.get("Content-Encoding") {
467                match content_encoding.to_str().unwrap_or_default() {
468                    "gzip" => {
469                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
470                        let _ = enc.write_all(ser.into_inner().as_slice());
471                        match enc.finish() {
472                            Ok(buf) => {
473                                local_req_builder = local_req_builder.body(buf);
474                            }
475                            Err(e) => return Err(datadog::Error::Io(e)),
476                        }
477                    }
478                    "deflate" => {
479                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
480                        let _ = enc.write_all(ser.into_inner().as_slice());
481                        match enc.finish() {
482                            Ok(buf) => {
483                                local_req_builder = local_req_builder.body(buf);
484                            }
485                            Err(e) => return Err(datadog::Error::Io(e)),
486                        }
487                    }
488                    "zstd1" => {
489                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
490                        let _ = enc.write_all(ser.into_inner().as_slice());
491                        match enc.finish() {
492                            Ok(buf) => {
493                                local_req_builder = local_req_builder.body(buf);
494                            }
495                            Err(e) => return Err(datadog::Error::Io(e)),
496                        }
497                    }
498                    _ => {
499                        local_req_builder = local_req_builder.body(ser.into_inner());
500                    }
501                }
502            } else {
503                local_req_builder = local_req_builder.body(ser.into_inner());
504            }
505        }
506
507        local_req_builder = local_req_builder.headers(headers);
508        let local_req = local_req_builder.build()?;
509        log::debug!("request content: {:?}", local_req.body());
510        let local_resp = local_client.execute(local_req).await?;
511
512        let local_status = local_resp.status();
513        let local_content = local_resp.text().await?;
514        log::debug!("response content: {}", local_content);
515
516        if !local_status.is_client_error() && !local_status.is_server_error() {
517            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
518                Ok(e) => {
519                    return Ok(datadog::ResponseContent {
520                        status: local_status,
521                        content: local_content,
522                        entity: Some(e),
523                    })
524                }
525                Err(e) => return Err(datadog::Error::Serde(e)),
526            };
527        } else {
528            let local_entity: Option<AssignCaseError> = serde_json::from_str(&local_content).ok();
529            let local_error = datadog::ResponseContent {
530                status: local_status,
531                content: local_content,
532                entity: local_entity,
533            };
534            Err(datadog::Error::ResponseError(local_error))
535        }
536    }
537
538    /// Create a Case
539    pub async fn create_case(
540        &self,
541        body: crate::datadogV2::model::CaseCreateRequest,
542    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<CreateCaseError>> {
543        match self.create_case_with_http_info(body).await {
544            Ok(response_content) => {
545                if let Some(e) = response_content.entity {
546                    Ok(e)
547                } else {
548                    Err(datadog::Error::Serde(serde::de::Error::custom(
549                        "response content was None",
550                    )))
551                }
552            }
553            Err(err) => Err(err),
554        }
555    }
556
557    /// Create a Case
558    pub async fn create_case_with_http_info(
559        &self,
560        body: crate::datadogV2::model::CaseCreateRequest,
561    ) -> Result<
562        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
563        datadog::Error<CreateCaseError>,
564    > {
565        let local_configuration = &self.config;
566        let operation_id = "v2.create_case";
567
568        let local_client = &self.client;
569
570        let local_uri_str = format!(
571            "{}/api/v2/cases",
572            local_configuration.get_operation_host(operation_id)
573        );
574        let mut local_req_builder =
575            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
576
577        // build headers
578        let mut headers = HeaderMap::new();
579        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
580        headers.insert("Accept", HeaderValue::from_static("application/json"));
581
582        // build user agent
583        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
584            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
585            Err(e) => {
586                log::warn!("Failed to parse user agent header: {e}, falling back to default");
587                headers.insert(
588                    reqwest::header::USER_AGENT,
589                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
590                )
591            }
592        };
593
594        // build auth
595        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
596            headers.insert(
597                "DD-API-KEY",
598                HeaderValue::from_str(local_key.key.as_str())
599                    .expect("failed to parse DD-API-KEY header"),
600            );
601        };
602        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
603            headers.insert(
604                "DD-APPLICATION-KEY",
605                HeaderValue::from_str(local_key.key.as_str())
606                    .expect("failed to parse DD-APPLICATION-KEY header"),
607            );
608        };
609
610        // build body parameters
611        let output = Vec::new();
612        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
613        if body.serialize(&mut ser).is_ok() {
614            if let Some(content_encoding) = headers.get("Content-Encoding") {
615                match content_encoding.to_str().unwrap_or_default() {
616                    "gzip" => {
617                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
618                        let _ = enc.write_all(ser.into_inner().as_slice());
619                        match enc.finish() {
620                            Ok(buf) => {
621                                local_req_builder = local_req_builder.body(buf);
622                            }
623                            Err(e) => return Err(datadog::Error::Io(e)),
624                        }
625                    }
626                    "deflate" => {
627                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
628                        let _ = enc.write_all(ser.into_inner().as_slice());
629                        match enc.finish() {
630                            Ok(buf) => {
631                                local_req_builder = local_req_builder.body(buf);
632                            }
633                            Err(e) => return Err(datadog::Error::Io(e)),
634                        }
635                    }
636                    "zstd1" => {
637                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
638                        let _ = enc.write_all(ser.into_inner().as_slice());
639                        match enc.finish() {
640                            Ok(buf) => {
641                                local_req_builder = local_req_builder.body(buf);
642                            }
643                            Err(e) => return Err(datadog::Error::Io(e)),
644                        }
645                    }
646                    _ => {
647                        local_req_builder = local_req_builder.body(ser.into_inner());
648                    }
649                }
650            } else {
651                local_req_builder = local_req_builder.body(ser.into_inner());
652            }
653        }
654
655        local_req_builder = local_req_builder.headers(headers);
656        let local_req = local_req_builder.build()?;
657        log::debug!("request content: {:?}", local_req.body());
658        let local_resp = local_client.execute(local_req).await?;
659
660        let local_status = local_resp.status();
661        let local_content = local_resp.text().await?;
662        log::debug!("response content: {}", local_content);
663
664        if !local_status.is_client_error() && !local_status.is_server_error() {
665            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
666                Ok(e) => {
667                    return Ok(datadog::ResponseContent {
668                        status: local_status,
669                        content: local_content,
670                        entity: Some(e),
671                    })
672                }
673                Err(e) => return Err(datadog::Error::Serde(e)),
674            };
675        } else {
676            let local_entity: Option<CreateCaseError> = serde_json::from_str(&local_content).ok();
677            let local_error = datadog::ResponseContent {
678                status: local_status,
679                content: local_content,
680                entity: local_entity,
681            };
682            Err(datadog::Error::ResponseError(local_error))
683        }
684    }
685
686    /// Create a project.
687    pub async fn create_project(
688        &self,
689        body: crate::datadogV2::model::ProjectCreateRequest,
690    ) -> Result<crate::datadogV2::model::ProjectResponse, datadog::Error<CreateProjectError>> {
691        match self.create_project_with_http_info(body).await {
692            Ok(response_content) => {
693                if let Some(e) = response_content.entity {
694                    Ok(e)
695                } else {
696                    Err(datadog::Error::Serde(serde::de::Error::custom(
697                        "response content was None",
698                    )))
699                }
700            }
701            Err(err) => Err(err),
702        }
703    }
704
705    /// Create a project.
706    pub async fn create_project_with_http_info(
707        &self,
708        body: crate::datadogV2::model::ProjectCreateRequest,
709    ) -> Result<
710        datadog::ResponseContent<crate::datadogV2::model::ProjectResponse>,
711        datadog::Error<CreateProjectError>,
712    > {
713        let local_configuration = &self.config;
714        let operation_id = "v2.create_project";
715
716        let local_client = &self.client;
717
718        let local_uri_str = format!(
719            "{}/api/v2/cases/projects",
720            local_configuration.get_operation_host(operation_id)
721        );
722        let mut local_req_builder =
723            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
724
725        // build headers
726        let mut headers = HeaderMap::new();
727        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
728        headers.insert("Accept", HeaderValue::from_static("application/json"));
729
730        // build user agent
731        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
732            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
733            Err(e) => {
734                log::warn!("Failed to parse user agent header: {e}, falling back to default");
735                headers.insert(
736                    reqwest::header::USER_AGENT,
737                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
738                )
739            }
740        };
741
742        // build auth
743        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
744            headers.insert(
745                "DD-API-KEY",
746                HeaderValue::from_str(local_key.key.as_str())
747                    .expect("failed to parse DD-API-KEY header"),
748            );
749        };
750        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
751            headers.insert(
752                "DD-APPLICATION-KEY",
753                HeaderValue::from_str(local_key.key.as_str())
754                    .expect("failed to parse DD-APPLICATION-KEY header"),
755            );
756        };
757
758        // build body parameters
759        let output = Vec::new();
760        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
761        if body.serialize(&mut ser).is_ok() {
762            if let Some(content_encoding) = headers.get("Content-Encoding") {
763                match content_encoding.to_str().unwrap_or_default() {
764                    "gzip" => {
765                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
766                        let _ = enc.write_all(ser.into_inner().as_slice());
767                        match enc.finish() {
768                            Ok(buf) => {
769                                local_req_builder = local_req_builder.body(buf);
770                            }
771                            Err(e) => return Err(datadog::Error::Io(e)),
772                        }
773                    }
774                    "deflate" => {
775                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
776                        let _ = enc.write_all(ser.into_inner().as_slice());
777                        match enc.finish() {
778                            Ok(buf) => {
779                                local_req_builder = local_req_builder.body(buf);
780                            }
781                            Err(e) => return Err(datadog::Error::Io(e)),
782                        }
783                    }
784                    "zstd1" => {
785                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
786                        let _ = enc.write_all(ser.into_inner().as_slice());
787                        match enc.finish() {
788                            Ok(buf) => {
789                                local_req_builder = local_req_builder.body(buf);
790                            }
791                            Err(e) => return Err(datadog::Error::Io(e)),
792                        }
793                    }
794                    _ => {
795                        local_req_builder = local_req_builder.body(ser.into_inner());
796                    }
797                }
798            } else {
799                local_req_builder = local_req_builder.body(ser.into_inner());
800            }
801        }
802
803        local_req_builder = local_req_builder.headers(headers);
804        let local_req = local_req_builder.build()?;
805        log::debug!("request content: {:?}", local_req.body());
806        let local_resp = local_client.execute(local_req).await?;
807
808        let local_status = local_resp.status();
809        let local_content = local_resp.text().await?;
810        log::debug!("response content: {}", local_content);
811
812        if !local_status.is_client_error() && !local_status.is_server_error() {
813            match serde_json::from_str::<crate::datadogV2::model::ProjectResponse>(&local_content) {
814                Ok(e) => {
815                    return Ok(datadog::ResponseContent {
816                        status: local_status,
817                        content: local_content,
818                        entity: Some(e),
819                    })
820                }
821                Err(e) => return Err(datadog::Error::Serde(e)),
822            };
823        } else {
824            let local_entity: Option<CreateProjectError> =
825                serde_json::from_str(&local_content).ok();
826            let local_error = datadog::ResponseContent {
827                status: local_status,
828                content: local_content,
829                entity: local_entity,
830            };
831            Err(datadog::Error::ResponseError(local_error))
832        }
833    }
834
835    /// Remove a project using the project's `id`.
836    pub async fn delete_project(
837        &self,
838        project_id: String,
839    ) -> Result<(), datadog::Error<DeleteProjectError>> {
840        match self.delete_project_with_http_info(project_id).await {
841            Ok(_) => Ok(()),
842            Err(err) => Err(err),
843        }
844    }
845
846    /// Remove a project using the project's `id`.
847    pub async fn delete_project_with_http_info(
848        &self,
849        project_id: String,
850    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteProjectError>> {
851        let local_configuration = &self.config;
852        let operation_id = "v2.delete_project";
853
854        let local_client = &self.client;
855
856        let local_uri_str = format!(
857            "{}/api/v2/cases/projects/{project_id}",
858            local_configuration.get_operation_host(operation_id),
859            project_id = datadog::urlencode(project_id)
860        );
861        let mut local_req_builder =
862            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
863
864        // build headers
865        let mut headers = HeaderMap::new();
866        headers.insert("Accept", HeaderValue::from_static("*/*"));
867
868        // build user agent
869        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
870            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
871            Err(e) => {
872                log::warn!("Failed to parse user agent header: {e}, falling back to default");
873                headers.insert(
874                    reqwest::header::USER_AGENT,
875                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
876                )
877            }
878        };
879
880        // build auth
881        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
882            headers.insert(
883                "DD-API-KEY",
884                HeaderValue::from_str(local_key.key.as_str())
885                    .expect("failed to parse DD-API-KEY header"),
886            );
887        };
888        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
889            headers.insert(
890                "DD-APPLICATION-KEY",
891                HeaderValue::from_str(local_key.key.as_str())
892                    .expect("failed to parse DD-APPLICATION-KEY header"),
893            );
894        };
895
896        local_req_builder = local_req_builder.headers(headers);
897        let local_req = local_req_builder.build()?;
898        log::debug!("request content: {:?}", local_req.body());
899        let local_resp = local_client.execute(local_req).await?;
900
901        let local_status = local_resp.status();
902        let local_content = local_resp.text().await?;
903        log::debug!("response content: {}", local_content);
904
905        if !local_status.is_client_error() && !local_status.is_server_error() {
906            Ok(datadog::ResponseContent {
907                status: local_status,
908                content: local_content,
909                entity: None,
910            })
911        } else {
912            let local_entity: Option<DeleteProjectError> =
913                serde_json::from_str(&local_content).ok();
914            let local_error = datadog::ResponseContent {
915                status: local_status,
916                content: local_content,
917                entity: local_entity,
918            };
919            Err(datadog::Error::ResponseError(local_error))
920        }
921    }
922
923    /// Get the details of case by `case_id`
924    pub async fn get_case(
925        &self,
926        case_id: String,
927    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<GetCaseError>> {
928        match self.get_case_with_http_info(case_id).await {
929            Ok(response_content) => {
930                if let Some(e) = response_content.entity {
931                    Ok(e)
932                } else {
933                    Err(datadog::Error::Serde(serde::de::Error::custom(
934                        "response content was None",
935                    )))
936                }
937            }
938            Err(err) => Err(err),
939        }
940    }
941
942    /// Get the details of case by `case_id`
943    pub async fn get_case_with_http_info(
944        &self,
945        case_id: String,
946    ) -> Result<
947        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
948        datadog::Error<GetCaseError>,
949    > {
950        let local_configuration = &self.config;
951        let operation_id = "v2.get_case";
952
953        let local_client = &self.client;
954
955        let local_uri_str = format!(
956            "{}/api/v2/cases/{case_id}",
957            local_configuration.get_operation_host(operation_id),
958            case_id = datadog::urlencode(case_id)
959        );
960        let mut local_req_builder =
961            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
962
963        // build headers
964        let mut headers = HeaderMap::new();
965        headers.insert("Accept", HeaderValue::from_static("application/json"));
966
967        // build user agent
968        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
969            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
970            Err(e) => {
971                log::warn!("Failed to parse user agent header: {e}, falling back to default");
972                headers.insert(
973                    reqwest::header::USER_AGENT,
974                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
975                )
976            }
977        };
978
979        // build auth
980        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
981            headers.insert(
982                "DD-API-KEY",
983                HeaderValue::from_str(local_key.key.as_str())
984                    .expect("failed to parse DD-API-KEY header"),
985            );
986        };
987        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
988            headers.insert(
989                "DD-APPLICATION-KEY",
990                HeaderValue::from_str(local_key.key.as_str())
991                    .expect("failed to parse DD-APPLICATION-KEY header"),
992            );
993        };
994
995        local_req_builder = local_req_builder.headers(headers);
996        let local_req = local_req_builder.build()?;
997        log::debug!("request content: {:?}", local_req.body());
998        let local_resp = local_client.execute(local_req).await?;
999
1000        let local_status = local_resp.status();
1001        let local_content = local_resp.text().await?;
1002        log::debug!("response content: {}", local_content);
1003
1004        if !local_status.is_client_error() && !local_status.is_server_error() {
1005            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
1006                Ok(e) => {
1007                    return Ok(datadog::ResponseContent {
1008                        status: local_status,
1009                        content: local_content,
1010                        entity: Some(e),
1011                    })
1012                }
1013                Err(e) => return Err(datadog::Error::Serde(e)),
1014            };
1015        } else {
1016            let local_entity: Option<GetCaseError> = serde_json::from_str(&local_content).ok();
1017            let local_error = datadog::ResponseContent {
1018                status: local_status,
1019                content: local_content,
1020                entity: local_entity,
1021            };
1022            Err(datadog::Error::ResponseError(local_error))
1023        }
1024    }
1025
1026    /// Get the details of a project by `project_id`.
1027    pub async fn get_project(
1028        &self,
1029        project_id: String,
1030    ) -> Result<crate::datadogV2::model::ProjectResponse, datadog::Error<GetProjectError>> {
1031        match self.get_project_with_http_info(project_id).await {
1032            Ok(response_content) => {
1033                if let Some(e) = response_content.entity {
1034                    Ok(e)
1035                } else {
1036                    Err(datadog::Error::Serde(serde::de::Error::custom(
1037                        "response content was None",
1038                    )))
1039                }
1040            }
1041            Err(err) => Err(err),
1042        }
1043    }
1044
1045    /// Get the details of a project by `project_id`.
1046    pub async fn get_project_with_http_info(
1047        &self,
1048        project_id: String,
1049    ) -> Result<
1050        datadog::ResponseContent<crate::datadogV2::model::ProjectResponse>,
1051        datadog::Error<GetProjectError>,
1052    > {
1053        let local_configuration = &self.config;
1054        let operation_id = "v2.get_project";
1055
1056        let local_client = &self.client;
1057
1058        let local_uri_str = format!(
1059            "{}/api/v2/cases/projects/{project_id}",
1060            local_configuration.get_operation_host(operation_id),
1061            project_id = datadog::urlencode(project_id)
1062        );
1063        let mut local_req_builder =
1064            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1065
1066        // build headers
1067        let mut headers = HeaderMap::new();
1068        headers.insert("Accept", HeaderValue::from_static("application/json"));
1069
1070        // build user agent
1071        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1072            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1073            Err(e) => {
1074                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1075                headers.insert(
1076                    reqwest::header::USER_AGENT,
1077                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1078                )
1079            }
1080        };
1081
1082        // build auth
1083        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1084            headers.insert(
1085                "DD-API-KEY",
1086                HeaderValue::from_str(local_key.key.as_str())
1087                    .expect("failed to parse DD-API-KEY header"),
1088            );
1089        };
1090        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1091            headers.insert(
1092                "DD-APPLICATION-KEY",
1093                HeaderValue::from_str(local_key.key.as_str())
1094                    .expect("failed to parse DD-APPLICATION-KEY header"),
1095            );
1096        };
1097
1098        local_req_builder = local_req_builder.headers(headers);
1099        let local_req = local_req_builder.build()?;
1100        log::debug!("request content: {:?}", local_req.body());
1101        let local_resp = local_client.execute(local_req).await?;
1102
1103        let local_status = local_resp.status();
1104        let local_content = local_resp.text().await?;
1105        log::debug!("response content: {}", local_content);
1106
1107        if !local_status.is_client_error() && !local_status.is_server_error() {
1108            match serde_json::from_str::<crate::datadogV2::model::ProjectResponse>(&local_content) {
1109                Ok(e) => {
1110                    return Ok(datadog::ResponseContent {
1111                        status: local_status,
1112                        content: local_content,
1113                        entity: Some(e),
1114                    })
1115                }
1116                Err(e) => return Err(datadog::Error::Serde(e)),
1117            };
1118        } else {
1119            let local_entity: Option<GetProjectError> = 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    /// Get all projects.
1130    pub async fn get_projects(
1131        &self,
1132    ) -> Result<crate::datadogV2::model::ProjectsResponse, datadog::Error<GetProjectsError>> {
1133        match self.get_projects_with_http_info().await {
1134            Ok(response_content) => {
1135                if let Some(e) = response_content.entity {
1136                    Ok(e)
1137                } else {
1138                    Err(datadog::Error::Serde(serde::de::Error::custom(
1139                        "response content was None",
1140                    )))
1141                }
1142            }
1143            Err(err) => Err(err),
1144        }
1145    }
1146
1147    /// Get all projects.
1148    pub async fn get_projects_with_http_info(
1149        &self,
1150    ) -> Result<
1151        datadog::ResponseContent<crate::datadogV2::model::ProjectsResponse>,
1152        datadog::Error<GetProjectsError>,
1153    > {
1154        let local_configuration = &self.config;
1155        let operation_id = "v2.get_projects";
1156
1157        let local_client = &self.client;
1158
1159        let local_uri_str = format!(
1160            "{}/api/v2/cases/projects",
1161            local_configuration.get_operation_host(operation_id)
1162        );
1163        let mut local_req_builder =
1164            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1165
1166        // build headers
1167        let mut headers = HeaderMap::new();
1168        headers.insert("Accept", HeaderValue::from_static("application/json"));
1169
1170        // build user agent
1171        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1172            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1173            Err(e) => {
1174                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1175                headers.insert(
1176                    reqwest::header::USER_AGENT,
1177                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1178                )
1179            }
1180        };
1181
1182        // build auth
1183        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1184            headers.insert(
1185                "DD-API-KEY",
1186                HeaderValue::from_str(local_key.key.as_str())
1187                    .expect("failed to parse DD-API-KEY header"),
1188            );
1189        };
1190        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1191            headers.insert(
1192                "DD-APPLICATION-KEY",
1193                HeaderValue::from_str(local_key.key.as_str())
1194                    .expect("failed to parse DD-APPLICATION-KEY header"),
1195            );
1196        };
1197
1198        local_req_builder = local_req_builder.headers(headers);
1199        let local_req = local_req_builder.build()?;
1200        log::debug!("request content: {:?}", local_req.body());
1201        let local_resp = local_client.execute(local_req).await?;
1202
1203        let local_status = local_resp.status();
1204        let local_content = local_resp.text().await?;
1205        log::debug!("response content: {}", local_content);
1206
1207        if !local_status.is_client_error() && !local_status.is_server_error() {
1208            match serde_json::from_str::<crate::datadogV2::model::ProjectsResponse>(&local_content)
1209            {
1210                Ok(e) => {
1211                    return Ok(datadog::ResponseContent {
1212                        status: local_status,
1213                        content: local_content,
1214                        entity: Some(e),
1215                    })
1216                }
1217                Err(e) => return Err(datadog::Error::Serde(e)),
1218            };
1219        } else {
1220            let local_entity: Option<GetProjectsError> = serde_json::from_str(&local_content).ok();
1221            let local_error = datadog::ResponseContent {
1222                status: local_status,
1223                content: local_content,
1224                entity: local_entity,
1225            };
1226            Err(datadog::Error::ResponseError(local_error))
1227        }
1228    }
1229
1230    /// Search cases.
1231    pub async fn search_cases(
1232        &self,
1233        params: SearchCasesOptionalParams,
1234    ) -> Result<crate::datadogV2::model::CasesResponse, datadog::Error<SearchCasesError>> {
1235        match self.search_cases_with_http_info(params).await {
1236            Ok(response_content) => {
1237                if let Some(e) = response_content.entity {
1238                    Ok(e)
1239                } else {
1240                    Err(datadog::Error::Serde(serde::de::Error::custom(
1241                        "response content was None",
1242                    )))
1243                }
1244            }
1245            Err(err) => Err(err),
1246        }
1247    }
1248
1249    pub fn search_cases_with_pagination(
1250        &self,
1251        mut params: SearchCasesOptionalParams,
1252    ) -> impl Stream<Item = Result<crate::datadogV2::model::Case, datadog::Error<SearchCasesError>>> + '_
1253    {
1254        try_stream! {
1255            let mut page_size: i64 = 10;
1256            if params.page_size.is_none() {
1257                params.page_size = Some(page_size);
1258            } else {
1259                page_size = params.page_size.unwrap().clone();
1260            }
1261            if params.page_number.is_none() {
1262                params.page_number = Some(0);
1263            }
1264            loop {
1265                let resp = self.search_cases(params.clone()).await?;
1266                let Some(data) = resp.data else { break };
1267
1268                let r = data;
1269                let count = r.len();
1270                for team in r {
1271                    yield team;
1272                }
1273
1274                if count < page_size as usize {
1275                    break;
1276                }
1277                params.page_number = Some(params.page_number.unwrap() + 1);
1278            }
1279        }
1280    }
1281
1282    /// Search cases.
1283    pub async fn search_cases_with_http_info(
1284        &self,
1285        params: SearchCasesOptionalParams,
1286    ) -> Result<
1287        datadog::ResponseContent<crate::datadogV2::model::CasesResponse>,
1288        datadog::Error<SearchCasesError>,
1289    > {
1290        let local_configuration = &self.config;
1291        let operation_id = "v2.search_cases";
1292
1293        // unbox and build optional parameters
1294        let page_size = params.page_size;
1295        let page_number = params.page_number;
1296        let sort_field = params.sort_field;
1297        let filter = params.filter;
1298        let sort_asc = params.sort_asc;
1299
1300        let local_client = &self.client;
1301
1302        let local_uri_str = format!(
1303            "{}/api/v2/cases",
1304            local_configuration.get_operation_host(operation_id)
1305        );
1306        let mut local_req_builder =
1307            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1308
1309        if let Some(ref local_query_param) = page_size {
1310            local_req_builder =
1311                local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1312        };
1313        if let Some(ref local_query_param) = page_number {
1314            local_req_builder =
1315                local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
1316        };
1317        if let Some(ref local_query_param) = sort_field {
1318            local_req_builder =
1319                local_req_builder.query(&[("sort[field]", &local_query_param.to_string())]);
1320        };
1321        if let Some(ref local_query_param) = filter {
1322            local_req_builder =
1323                local_req_builder.query(&[("filter", &local_query_param.to_string())]);
1324        };
1325        if let Some(ref local_query_param) = sort_asc {
1326            local_req_builder =
1327                local_req_builder.query(&[("sort[asc]", &local_query_param.to_string())]);
1328        };
1329
1330        // build headers
1331        let mut headers = HeaderMap::new();
1332        headers.insert("Accept", HeaderValue::from_static("application/json"));
1333
1334        // build user agent
1335        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1336            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1337            Err(e) => {
1338                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1339                headers.insert(
1340                    reqwest::header::USER_AGENT,
1341                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1342                )
1343            }
1344        };
1345
1346        // build auth
1347        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1348            headers.insert(
1349                "DD-API-KEY",
1350                HeaderValue::from_str(local_key.key.as_str())
1351                    .expect("failed to parse DD-API-KEY header"),
1352            );
1353        };
1354        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1355            headers.insert(
1356                "DD-APPLICATION-KEY",
1357                HeaderValue::from_str(local_key.key.as_str())
1358                    .expect("failed to parse DD-APPLICATION-KEY header"),
1359            );
1360        };
1361
1362        local_req_builder = local_req_builder.headers(headers);
1363        let local_req = local_req_builder.build()?;
1364        log::debug!("request content: {:?}", local_req.body());
1365        let local_resp = local_client.execute(local_req).await?;
1366
1367        let local_status = local_resp.status();
1368        let local_content = local_resp.text().await?;
1369        log::debug!("response content: {}", local_content);
1370
1371        if !local_status.is_client_error() && !local_status.is_server_error() {
1372            match serde_json::from_str::<crate::datadogV2::model::CasesResponse>(&local_content) {
1373                Ok(e) => {
1374                    return Ok(datadog::ResponseContent {
1375                        status: local_status,
1376                        content: local_content,
1377                        entity: Some(e),
1378                    })
1379                }
1380                Err(e) => return Err(datadog::Error::Serde(e)),
1381            };
1382        } else {
1383            let local_entity: Option<SearchCasesError> = serde_json::from_str(&local_content).ok();
1384            let local_error = datadog::ResponseContent {
1385                status: local_status,
1386                content: local_content,
1387                entity: local_entity,
1388            };
1389            Err(datadog::Error::ResponseError(local_error))
1390        }
1391    }
1392
1393    /// Unarchive case
1394    pub async fn unarchive_case(
1395        &self,
1396        case_id: String,
1397        body: crate::datadogV2::model::CaseEmptyRequest,
1398    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UnarchiveCaseError>> {
1399        match self.unarchive_case_with_http_info(case_id, body).await {
1400            Ok(response_content) => {
1401                if let Some(e) = response_content.entity {
1402                    Ok(e)
1403                } else {
1404                    Err(datadog::Error::Serde(serde::de::Error::custom(
1405                        "response content was None",
1406                    )))
1407                }
1408            }
1409            Err(err) => Err(err),
1410        }
1411    }
1412
1413    /// Unarchive case
1414    pub async fn unarchive_case_with_http_info(
1415        &self,
1416        case_id: String,
1417        body: crate::datadogV2::model::CaseEmptyRequest,
1418    ) -> Result<
1419        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
1420        datadog::Error<UnarchiveCaseError>,
1421    > {
1422        let local_configuration = &self.config;
1423        let operation_id = "v2.unarchive_case";
1424
1425        let local_client = &self.client;
1426
1427        let local_uri_str = format!(
1428            "{}/api/v2/cases/{case_id}/unarchive",
1429            local_configuration.get_operation_host(operation_id),
1430            case_id = datadog::urlencode(case_id)
1431        );
1432        let mut local_req_builder =
1433            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1434
1435        // build headers
1436        let mut headers = HeaderMap::new();
1437        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1438        headers.insert("Accept", HeaderValue::from_static("application/json"));
1439
1440        // build user agent
1441        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1442            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1443            Err(e) => {
1444                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1445                headers.insert(
1446                    reqwest::header::USER_AGENT,
1447                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1448                )
1449            }
1450        };
1451
1452        // build auth
1453        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1454            headers.insert(
1455                "DD-API-KEY",
1456                HeaderValue::from_str(local_key.key.as_str())
1457                    .expect("failed to parse DD-API-KEY header"),
1458            );
1459        };
1460        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1461            headers.insert(
1462                "DD-APPLICATION-KEY",
1463                HeaderValue::from_str(local_key.key.as_str())
1464                    .expect("failed to parse DD-APPLICATION-KEY header"),
1465            );
1466        };
1467
1468        // build body parameters
1469        let output = Vec::new();
1470        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1471        if body.serialize(&mut ser).is_ok() {
1472            if let Some(content_encoding) = headers.get("Content-Encoding") {
1473                match content_encoding.to_str().unwrap_or_default() {
1474                    "gzip" => {
1475                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1476                        let _ = enc.write_all(ser.into_inner().as_slice());
1477                        match enc.finish() {
1478                            Ok(buf) => {
1479                                local_req_builder = local_req_builder.body(buf);
1480                            }
1481                            Err(e) => return Err(datadog::Error::Io(e)),
1482                        }
1483                    }
1484                    "deflate" => {
1485                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1486                        let _ = enc.write_all(ser.into_inner().as_slice());
1487                        match enc.finish() {
1488                            Ok(buf) => {
1489                                local_req_builder = local_req_builder.body(buf);
1490                            }
1491                            Err(e) => return Err(datadog::Error::Io(e)),
1492                        }
1493                    }
1494                    "zstd1" => {
1495                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1496                        let _ = enc.write_all(ser.into_inner().as_slice());
1497                        match enc.finish() {
1498                            Ok(buf) => {
1499                                local_req_builder = local_req_builder.body(buf);
1500                            }
1501                            Err(e) => return Err(datadog::Error::Io(e)),
1502                        }
1503                    }
1504                    _ => {
1505                        local_req_builder = local_req_builder.body(ser.into_inner());
1506                    }
1507                }
1508            } else {
1509                local_req_builder = local_req_builder.body(ser.into_inner());
1510            }
1511        }
1512
1513        local_req_builder = local_req_builder.headers(headers);
1514        let local_req = local_req_builder.build()?;
1515        log::debug!("request content: {:?}", local_req.body());
1516        let local_resp = local_client.execute(local_req).await?;
1517
1518        let local_status = local_resp.status();
1519        let local_content = local_resp.text().await?;
1520        log::debug!("response content: {}", local_content);
1521
1522        if !local_status.is_client_error() && !local_status.is_server_error() {
1523            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
1524                Ok(e) => {
1525                    return Ok(datadog::ResponseContent {
1526                        status: local_status,
1527                        content: local_content,
1528                        entity: Some(e),
1529                    })
1530                }
1531                Err(e) => return Err(datadog::Error::Serde(e)),
1532            };
1533        } else {
1534            let local_entity: Option<UnarchiveCaseError> =
1535                serde_json::from_str(&local_content).ok();
1536            let local_error = datadog::ResponseContent {
1537                status: local_status,
1538                content: local_content,
1539                entity: local_entity,
1540            };
1541            Err(datadog::Error::ResponseError(local_error))
1542        }
1543    }
1544
1545    /// Unassign case
1546    pub async fn unassign_case(
1547        &self,
1548        case_id: String,
1549        body: crate::datadogV2::model::CaseEmptyRequest,
1550    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UnassignCaseError>> {
1551        match self.unassign_case_with_http_info(case_id, body).await {
1552            Ok(response_content) => {
1553                if let Some(e) = response_content.entity {
1554                    Ok(e)
1555                } else {
1556                    Err(datadog::Error::Serde(serde::de::Error::custom(
1557                        "response content was None",
1558                    )))
1559                }
1560            }
1561            Err(err) => Err(err),
1562        }
1563    }
1564
1565    /// Unassign case
1566    pub async fn unassign_case_with_http_info(
1567        &self,
1568        case_id: String,
1569        body: crate::datadogV2::model::CaseEmptyRequest,
1570    ) -> Result<
1571        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
1572        datadog::Error<UnassignCaseError>,
1573    > {
1574        let local_configuration = &self.config;
1575        let operation_id = "v2.unassign_case";
1576
1577        let local_client = &self.client;
1578
1579        let local_uri_str = format!(
1580            "{}/api/v2/cases/{case_id}/unassign",
1581            local_configuration.get_operation_host(operation_id),
1582            case_id = datadog::urlencode(case_id)
1583        );
1584        let mut local_req_builder =
1585            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1586
1587        // build headers
1588        let mut headers = HeaderMap::new();
1589        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1590        headers.insert("Accept", HeaderValue::from_static("application/json"));
1591
1592        // build user agent
1593        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1594            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1595            Err(e) => {
1596                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1597                headers.insert(
1598                    reqwest::header::USER_AGENT,
1599                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1600                )
1601            }
1602        };
1603
1604        // build auth
1605        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1606            headers.insert(
1607                "DD-API-KEY",
1608                HeaderValue::from_str(local_key.key.as_str())
1609                    .expect("failed to parse DD-API-KEY header"),
1610            );
1611        };
1612        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1613            headers.insert(
1614                "DD-APPLICATION-KEY",
1615                HeaderValue::from_str(local_key.key.as_str())
1616                    .expect("failed to parse DD-APPLICATION-KEY header"),
1617            );
1618        };
1619
1620        // build body parameters
1621        let output = Vec::new();
1622        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1623        if body.serialize(&mut ser).is_ok() {
1624            if let Some(content_encoding) = headers.get("Content-Encoding") {
1625                match content_encoding.to_str().unwrap_or_default() {
1626                    "gzip" => {
1627                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1628                        let _ = enc.write_all(ser.into_inner().as_slice());
1629                        match enc.finish() {
1630                            Ok(buf) => {
1631                                local_req_builder = local_req_builder.body(buf);
1632                            }
1633                            Err(e) => return Err(datadog::Error::Io(e)),
1634                        }
1635                    }
1636                    "deflate" => {
1637                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1638                        let _ = enc.write_all(ser.into_inner().as_slice());
1639                        match enc.finish() {
1640                            Ok(buf) => {
1641                                local_req_builder = local_req_builder.body(buf);
1642                            }
1643                            Err(e) => return Err(datadog::Error::Io(e)),
1644                        }
1645                    }
1646                    "zstd1" => {
1647                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1648                        let _ = enc.write_all(ser.into_inner().as_slice());
1649                        match enc.finish() {
1650                            Ok(buf) => {
1651                                local_req_builder = local_req_builder.body(buf);
1652                            }
1653                            Err(e) => return Err(datadog::Error::Io(e)),
1654                        }
1655                    }
1656                    _ => {
1657                        local_req_builder = local_req_builder.body(ser.into_inner());
1658                    }
1659                }
1660            } else {
1661                local_req_builder = local_req_builder.body(ser.into_inner());
1662            }
1663        }
1664
1665        local_req_builder = local_req_builder.headers(headers);
1666        let local_req = local_req_builder.build()?;
1667        log::debug!("request content: {:?}", local_req.body());
1668        let local_resp = local_client.execute(local_req).await?;
1669
1670        let local_status = local_resp.status();
1671        let local_content = local_resp.text().await?;
1672        log::debug!("response content: {}", local_content);
1673
1674        if !local_status.is_client_error() && !local_status.is_server_error() {
1675            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
1676                Ok(e) => {
1677                    return Ok(datadog::ResponseContent {
1678                        status: local_status,
1679                        content: local_content,
1680                        entity: Some(e),
1681                    })
1682                }
1683                Err(e) => return Err(datadog::Error::Serde(e)),
1684            };
1685        } else {
1686            let local_entity: Option<UnassignCaseError> = serde_json::from_str(&local_content).ok();
1687            let local_error = datadog::ResponseContent {
1688                status: local_status,
1689                content: local_content,
1690                entity: local_entity,
1691            };
1692            Err(datadog::Error::ResponseError(local_error))
1693        }
1694    }
1695
1696    /// Update case attributes
1697    pub async fn update_attributes(
1698        &self,
1699        case_id: String,
1700        body: crate::datadogV2::model::CaseUpdateAttributesRequest,
1701    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdateAttributesError>> {
1702        match self.update_attributes_with_http_info(case_id, body).await {
1703            Ok(response_content) => {
1704                if let Some(e) = response_content.entity {
1705                    Ok(e)
1706                } else {
1707                    Err(datadog::Error::Serde(serde::de::Error::custom(
1708                        "response content was None",
1709                    )))
1710                }
1711            }
1712            Err(err) => Err(err),
1713        }
1714    }
1715
1716    /// Update case attributes
1717    pub async fn update_attributes_with_http_info(
1718        &self,
1719        case_id: String,
1720        body: crate::datadogV2::model::CaseUpdateAttributesRequest,
1721    ) -> Result<
1722        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
1723        datadog::Error<UpdateAttributesError>,
1724    > {
1725        let local_configuration = &self.config;
1726        let operation_id = "v2.update_attributes";
1727
1728        let local_client = &self.client;
1729
1730        let local_uri_str = format!(
1731            "{}/api/v2/cases/{case_id}/attributes",
1732            local_configuration.get_operation_host(operation_id),
1733            case_id = datadog::urlencode(case_id)
1734        );
1735        let mut local_req_builder =
1736            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1737
1738        // build headers
1739        let mut headers = HeaderMap::new();
1740        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1741        headers.insert("Accept", HeaderValue::from_static("application/json"));
1742
1743        // build user agent
1744        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1745            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1746            Err(e) => {
1747                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1748                headers.insert(
1749                    reqwest::header::USER_AGENT,
1750                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1751                )
1752            }
1753        };
1754
1755        // build auth
1756        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1757            headers.insert(
1758                "DD-API-KEY",
1759                HeaderValue::from_str(local_key.key.as_str())
1760                    .expect("failed to parse DD-API-KEY header"),
1761            );
1762        };
1763        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1764            headers.insert(
1765                "DD-APPLICATION-KEY",
1766                HeaderValue::from_str(local_key.key.as_str())
1767                    .expect("failed to parse DD-APPLICATION-KEY header"),
1768            );
1769        };
1770
1771        // build body parameters
1772        let output = Vec::new();
1773        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1774        if body.serialize(&mut ser).is_ok() {
1775            if let Some(content_encoding) = headers.get("Content-Encoding") {
1776                match content_encoding.to_str().unwrap_or_default() {
1777                    "gzip" => {
1778                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1779                        let _ = enc.write_all(ser.into_inner().as_slice());
1780                        match enc.finish() {
1781                            Ok(buf) => {
1782                                local_req_builder = local_req_builder.body(buf);
1783                            }
1784                            Err(e) => return Err(datadog::Error::Io(e)),
1785                        }
1786                    }
1787                    "deflate" => {
1788                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1789                        let _ = enc.write_all(ser.into_inner().as_slice());
1790                        match enc.finish() {
1791                            Ok(buf) => {
1792                                local_req_builder = local_req_builder.body(buf);
1793                            }
1794                            Err(e) => return Err(datadog::Error::Io(e)),
1795                        }
1796                    }
1797                    "zstd1" => {
1798                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1799                        let _ = enc.write_all(ser.into_inner().as_slice());
1800                        match enc.finish() {
1801                            Ok(buf) => {
1802                                local_req_builder = local_req_builder.body(buf);
1803                            }
1804                            Err(e) => return Err(datadog::Error::Io(e)),
1805                        }
1806                    }
1807                    _ => {
1808                        local_req_builder = local_req_builder.body(ser.into_inner());
1809                    }
1810                }
1811            } else {
1812                local_req_builder = local_req_builder.body(ser.into_inner());
1813            }
1814        }
1815
1816        local_req_builder = local_req_builder.headers(headers);
1817        let local_req = local_req_builder.build()?;
1818        log::debug!("request content: {:?}", local_req.body());
1819        let local_resp = local_client.execute(local_req).await?;
1820
1821        let local_status = local_resp.status();
1822        let local_content = local_resp.text().await?;
1823        log::debug!("response content: {}", local_content);
1824
1825        if !local_status.is_client_error() && !local_status.is_server_error() {
1826            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
1827                Ok(e) => {
1828                    return Ok(datadog::ResponseContent {
1829                        status: local_status,
1830                        content: local_content,
1831                        entity: Some(e),
1832                    })
1833                }
1834                Err(e) => return Err(datadog::Error::Serde(e)),
1835            };
1836        } else {
1837            let local_entity: Option<UpdateAttributesError> =
1838                serde_json::from_str(&local_content).ok();
1839            let local_error = datadog::ResponseContent {
1840                status: local_status,
1841                content: local_content,
1842                entity: local_entity,
1843            };
1844            Err(datadog::Error::ResponseError(local_error))
1845        }
1846    }
1847
1848    /// Update case priority
1849    pub async fn update_priority(
1850        &self,
1851        case_id: String,
1852        body: crate::datadogV2::model::CaseUpdatePriorityRequest,
1853    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdatePriorityError>> {
1854        match self.update_priority_with_http_info(case_id, body).await {
1855            Ok(response_content) => {
1856                if let Some(e) = response_content.entity {
1857                    Ok(e)
1858                } else {
1859                    Err(datadog::Error::Serde(serde::de::Error::custom(
1860                        "response content was None",
1861                    )))
1862                }
1863            }
1864            Err(err) => Err(err),
1865        }
1866    }
1867
1868    /// Update case priority
1869    pub async fn update_priority_with_http_info(
1870        &self,
1871        case_id: String,
1872        body: crate::datadogV2::model::CaseUpdatePriorityRequest,
1873    ) -> Result<
1874        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
1875        datadog::Error<UpdatePriorityError>,
1876    > {
1877        let local_configuration = &self.config;
1878        let operation_id = "v2.update_priority";
1879
1880        let local_client = &self.client;
1881
1882        let local_uri_str = format!(
1883            "{}/api/v2/cases/{case_id}/priority",
1884            local_configuration.get_operation_host(operation_id),
1885            case_id = datadog::urlencode(case_id)
1886        );
1887        let mut local_req_builder =
1888            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1889
1890        // build headers
1891        let mut headers = HeaderMap::new();
1892        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1893        headers.insert("Accept", HeaderValue::from_static("application/json"));
1894
1895        // build user agent
1896        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1897            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1898            Err(e) => {
1899                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1900                headers.insert(
1901                    reqwest::header::USER_AGENT,
1902                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1903                )
1904            }
1905        };
1906
1907        // build auth
1908        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1909            headers.insert(
1910                "DD-API-KEY",
1911                HeaderValue::from_str(local_key.key.as_str())
1912                    .expect("failed to parse DD-API-KEY header"),
1913            );
1914        };
1915        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1916            headers.insert(
1917                "DD-APPLICATION-KEY",
1918                HeaderValue::from_str(local_key.key.as_str())
1919                    .expect("failed to parse DD-APPLICATION-KEY header"),
1920            );
1921        };
1922
1923        // build body parameters
1924        let output = Vec::new();
1925        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1926        if body.serialize(&mut ser).is_ok() {
1927            if let Some(content_encoding) = headers.get("Content-Encoding") {
1928                match content_encoding.to_str().unwrap_or_default() {
1929                    "gzip" => {
1930                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1931                        let _ = enc.write_all(ser.into_inner().as_slice());
1932                        match enc.finish() {
1933                            Ok(buf) => {
1934                                local_req_builder = local_req_builder.body(buf);
1935                            }
1936                            Err(e) => return Err(datadog::Error::Io(e)),
1937                        }
1938                    }
1939                    "deflate" => {
1940                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1941                        let _ = enc.write_all(ser.into_inner().as_slice());
1942                        match enc.finish() {
1943                            Ok(buf) => {
1944                                local_req_builder = local_req_builder.body(buf);
1945                            }
1946                            Err(e) => return Err(datadog::Error::Io(e)),
1947                        }
1948                    }
1949                    "zstd1" => {
1950                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1951                        let _ = enc.write_all(ser.into_inner().as_slice());
1952                        match enc.finish() {
1953                            Ok(buf) => {
1954                                local_req_builder = local_req_builder.body(buf);
1955                            }
1956                            Err(e) => return Err(datadog::Error::Io(e)),
1957                        }
1958                    }
1959                    _ => {
1960                        local_req_builder = local_req_builder.body(ser.into_inner());
1961                    }
1962                }
1963            } else {
1964                local_req_builder = local_req_builder.body(ser.into_inner());
1965            }
1966        }
1967
1968        local_req_builder = local_req_builder.headers(headers);
1969        let local_req = local_req_builder.build()?;
1970        log::debug!("request content: {:?}", local_req.body());
1971        let local_resp = local_client.execute(local_req).await?;
1972
1973        let local_status = local_resp.status();
1974        let local_content = local_resp.text().await?;
1975        log::debug!("response content: {}", local_content);
1976
1977        if !local_status.is_client_error() && !local_status.is_server_error() {
1978            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
1979                Ok(e) => {
1980                    return Ok(datadog::ResponseContent {
1981                        status: local_status,
1982                        content: local_content,
1983                        entity: Some(e),
1984                    })
1985                }
1986                Err(e) => return Err(datadog::Error::Serde(e)),
1987            };
1988        } else {
1989            let local_entity: Option<UpdatePriorityError> =
1990                serde_json::from_str(&local_content).ok();
1991            let local_error = datadog::ResponseContent {
1992                status: local_status,
1993                content: local_content,
1994                entity: local_entity,
1995            };
1996            Err(datadog::Error::ResponseError(local_error))
1997        }
1998    }
1999
2000    /// Update case status
2001    pub async fn update_status(
2002        &self,
2003        case_id: String,
2004        body: crate::datadogV2::model::CaseUpdateStatusRequest,
2005    ) -> Result<crate::datadogV2::model::CaseResponse, datadog::Error<UpdateStatusError>> {
2006        match self.update_status_with_http_info(case_id, body).await {
2007            Ok(response_content) => {
2008                if let Some(e) = response_content.entity {
2009                    Ok(e)
2010                } else {
2011                    Err(datadog::Error::Serde(serde::de::Error::custom(
2012                        "response content was None",
2013                    )))
2014                }
2015            }
2016            Err(err) => Err(err),
2017        }
2018    }
2019
2020    /// Update case status
2021    pub async fn update_status_with_http_info(
2022        &self,
2023        case_id: String,
2024        body: crate::datadogV2::model::CaseUpdateStatusRequest,
2025    ) -> Result<
2026        datadog::ResponseContent<crate::datadogV2::model::CaseResponse>,
2027        datadog::Error<UpdateStatusError>,
2028    > {
2029        let local_configuration = &self.config;
2030        let operation_id = "v2.update_status";
2031
2032        let local_client = &self.client;
2033
2034        let local_uri_str = format!(
2035            "{}/api/v2/cases/{case_id}/status",
2036            local_configuration.get_operation_host(operation_id),
2037            case_id = datadog::urlencode(case_id)
2038        );
2039        let mut local_req_builder =
2040            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2041
2042        // build headers
2043        let mut headers = HeaderMap::new();
2044        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2045        headers.insert("Accept", HeaderValue::from_static("application/json"));
2046
2047        // build user agent
2048        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2049            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2050            Err(e) => {
2051                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2052                headers.insert(
2053                    reqwest::header::USER_AGENT,
2054                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2055                )
2056            }
2057        };
2058
2059        // build auth
2060        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2061            headers.insert(
2062                "DD-API-KEY",
2063                HeaderValue::from_str(local_key.key.as_str())
2064                    .expect("failed to parse DD-API-KEY header"),
2065            );
2066        };
2067        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2068            headers.insert(
2069                "DD-APPLICATION-KEY",
2070                HeaderValue::from_str(local_key.key.as_str())
2071                    .expect("failed to parse DD-APPLICATION-KEY header"),
2072            );
2073        };
2074
2075        // build body parameters
2076        let output = Vec::new();
2077        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2078        if body.serialize(&mut ser).is_ok() {
2079            if let Some(content_encoding) = headers.get("Content-Encoding") {
2080                match content_encoding.to_str().unwrap_or_default() {
2081                    "gzip" => {
2082                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2083                        let _ = enc.write_all(ser.into_inner().as_slice());
2084                        match enc.finish() {
2085                            Ok(buf) => {
2086                                local_req_builder = local_req_builder.body(buf);
2087                            }
2088                            Err(e) => return Err(datadog::Error::Io(e)),
2089                        }
2090                    }
2091                    "deflate" => {
2092                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2093                        let _ = enc.write_all(ser.into_inner().as_slice());
2094                        match enc.finish() {
2095                            Ok(buf) => {
2096                                local_req_builder = local_req_builder.body(buf);
2097                            }
2098                            Err(e) => return Err(datadog::Error::Io(e)),
2099                        }
2100                    }
2101                    "zstd1" => {
2102                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2103                        let _ = enc.write_all(ser.into_inner().as_slice());
2104                        match enc.finish() {
2105                            Ok(buf) => {
2106                                local_req_builder = local_req_builder.body(buf);
2107                            }
2108                            Err(e) => return Err(datadog::Error::Io(e)),
2109                        }
2110                    }
2111                    _ => {
2112                        local_req_builder = local_req_builder.body(ser.into_inner());
2113                    }
2114                }
2115            } else {
2116                local_req_builder = local_req_builder.body(ser.into_inner());
2117            }
2118        }
2119
2120        local_req_builder = local_req_builder.headers(headers);
2121        let local_req = local_req_builder.build()?;
2122        log::debug!("request content: {:?}", local_req.body());
2123        let local_resp = local_client.execute(local_req).await?;
2124
2125        let local_status = local_resp.status();
2126        let local_content = local_resp.text().await?;
2127        log::debug!("response content: {}", local_content);
2128
2129        if !local_status.is_client_error() && !local_status.is_server_error() {
2130            match serde_json::from_str::<crate::datadogV2::model::CaseResponse>(&local_content) {
2131                Ok(e) => {
2132                    return Ok(datadog::ResponseContent {
2133                        status: local_status,
2134                        content: local_content,
2135                        entity: Some(e),
2136                    })
2137                }
2138                Err(e) => return Err(datadog::Error::Serde(e)),
2139            };
2140        } else {
2141            let local_entity: Option<UpdateStatusError> = serde_json::from_str(&local_content).ok();
2142            let local_error = datadog::ResponseContent {
2143                status: local_status,
2144                content: local_content,
2145                entity: local_entity,
2146            };
2147            Err(datadog::Error::ResponseError(local_error))
2148        }
2149    }
2150}