datadog_api_client/datadogV2/api/
api_incidents.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 log::warn;
12use reqwest::header::{HeaderMap, HeaderValue};
13use serde::{Deserialize, Serialize};
14use std::io::Write;
15
16/// CreateIncidentImpactOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::create_incident_impact`]
17#[non_exhaustive]
18#[derive(Clone, Default, Debug)]
19pub struct CreateIncidentImpactOptionalParams {
20    /// Specifies which related resources should be included in the response.
21    pub include: Option<Vec<crate::datadogV2::model::IncidentImpactRelatedObject>>,
22}
23
24impl CreateIncidentImpactOptionalParams {
25    /// Specifies which related resources should be included in the response.
26    pub fn include(
27        mut self,
28        value: Vec<crate::datadogV2::model::IncidentImpactRelatedObject>,
29    ) -> Self {
30        self.include = Some(value);
31        self
32    }
33}
34
35/// DeleteIncidentNotificationRuleOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::delete_incident_notification_rule`]
36#[non_exhaustive]
37#[derive(Clone, Default, Debug)]
38pub struct DeleteIncidentNotificationRuleOptionalParams {
39    /// Comma-separated list of resources to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`, `notification_template`
40    ///
41    pub include: Option<String>,
42}
43
44impl DeleteIncidentNotificationRuleOptionalParams {
45    /// Comma-separated list of resources to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`, `notification_template`
46    ///
47    pub fn include(mut self, value: String) -> Self {
48        self.include = Some(value);
49        self
50    }
51}
52
53/// DeleteIncidentNotificationTemplateOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::delete_incident_notification_template`]
54#[non_exhaustive]
55#[derive(Clone, Default, Debug)]
56pub struct DeleteIncidentNotificationTemplateOptionalParams {
57    /// Comma-separated list of relationships to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`
58    ///
59    pub include: Option<String>,
60}
61
62impl DeleteIncidentNotificationTemplateOptionalParams {
63    /// Comma-separated list of relationships to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`
64    ///
65    pub fn include(mut self, value: String) -> Self {
66        self.include = Some(value);
67        self
68    }
69}
70
71/// GetIncidentOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::get_incident`]
72#[non_exhaustive]
73#[derive(Clone, Default, Debug)]
74pub struct GetIncidentOptionalParams {
75    /// Specifies which types of related objects should be included in the response.
76    pub include: Option<Vec<crate::datadogV2::model::IncidentRelatedObject>>,
77}
78
79impl GetIncidentOptionalParams {
80    /// Specifies which types of related objects should be included in the response.
81    pub fn include(mut self, value: Vec<crate::datadogV2::model::IncidentRelatedObject>) -> Self {
82        self.include = Some(value);
83        self
84    }
85}
86
87/// GetIncidentNotificationRuleOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::get_incident_notification_rule`]
88#[non_exhaustive]
89#[derive(Clone, Default, Debug)]
90pub struct GetIncidentNotificationRuleOptionalParams {
91    /// Comma-separated list of resources to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`, `notification_template`
92    ///
93    pub include: Option<String>,
94}
95
96impl GetIncidentNotificationRuleOptionalParams {
97    /// Comma-separated list of resources to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`, `notification_template`
98    ///
99    pub fn include(mut self, value: String) -> Self {
100        self.include = Some(value);
101        self
102    }
103}
104
105/// GetIncidentNotificationTemplateOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::get_incident_notification_template`]
106#[non_exhaustive]
107#[derive(Clone, Default, Debug)]
108pub struct GetIncidentNotificationTemplateOptionalParams {
109    /// Comma-separated list of relationships to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`
110    ///
111    pub include: Option<String>,
112}
113
114impl GetIncidentNotificationTemplateOptionalParams {
115    /// Comma-separated list of relationships to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`
116    ///
117    pub fn include(mut self, value: String) -> Self {
118        self.include = Some(value);
119        self
120    }
121}
122
123/// ListIncidentAttachmentsOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::list_incident_attachments`]
124#[non_exhaustive]
125#[derive(Clone, Default, Debug)]
126pub struct ListIncidentAttachmentsOptionalParams {
127    /// Specifies which types of related objects are included in the response.
128    pub include: Option<Vec<crate::datadogV2::model::IncidentAttachmentRelatedObject>>,
129    /// Specifies which types of attachments are included in the response.
130    pub filter_attachment_type:
131        Option<Vec<crate::datadogV2::model::IncidentAttachmentAttachmentType>>,
132}
133
134impl ListIncidentAttachmentsOptionalParams {
135    /// Specifies which types of related objects are included in the response.
136    pub fn include(
137        mut self,
138        value: Vec<crate::datadogV2::model::IncidentAttachmentRelatedObject>,
139    ) -> Self {
140        self.include = Some(value);
141        self
142    }
143    /// Specifies which types of attachments are included in the response.
144    pub fn filter_attachment_type(
145        mut self,
146        value: Vec<crate::datadogV2::model::IncidentAttachmentAttachmentType>,
147    ) -> Self {
148        self.filter_attachment_type = Some(value);
149        self
150    }
151}
152
153/// ListIncidentImpactsOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::list_incident_impacts`]
154#[non_exhaustive]
155#[derive(Clone, Default, Debug)]
156pub struct ListIncidentImpactsOptionalParams {
157    /// Specifies which related resources should be included in the response.
158    pub include: Option<Vec<crate::datadogV2::model::IncidentImpactRelatedObject>>,
159}
160
161impl ListIncidentImpactsOptionalParams {
162    /// Specifies which related resources should be included in the response.
163    pub fn include(
164        mut self,
165        value: Vec<crate::datadogV2::model::IncidentImpactRelatedObject>,
166    ) -> Self {
167        self.include = Some(value);
168        self
169    }
170}
171
172/// ListIncidentNotificationRulesOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::list_incident_notification_rules`]
173#[non_exhaustive]
174#[derive(Clone, Default, Debug)]
175pub struct ListIncidentNotificationRulesOptionalParams {
176    /// Comma-separated list of resources to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`, `notification_template`
177    ///
178    pub include: Option<String>,
179}
180
181impl ListIncidentNotificationRulesOptionalParams {
182    /// Comma-separated list of resources to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`, `notification_template`
183    ///
184    pub fn include(mut self, value: String) -> Self {
185        self.include = Some(value);
186        self
187    }
188}
189
190/// ListIncidentNotificationTemplatesOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::list_incident_notification_templates`]
191#[non_exhaustive]
192#[derive(Clone, Default, Debug)]
193pub struct ListIncidentNotificationTemplatesOptionalParams {
194    /// Optional incident type ID filter.
195    pub filter_incident_type: Option<uuid::Uuid>,
196    /// Comma-separated list of relationships to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`
197    ///
198    pub include: Option<String>,
199}
200
201impl ListIncidentNotificationTemplatesOptionalParams {
202    /// Optional incident type ID filter.
203    pub fn filter_incident_type(mut self, value: uuid::Uuid) -> Self {
204        self.filter_incident_type = Some(value);
205        self
206    }
207    /// Comma-separated list of relationships to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`
208    ///
209    pub fn include(mut self, value: String) -> Self {
210        self.include = Some(value);
211        self
212    }
213}
214
215/// ListIncidentTypesOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::list_incident_types`]
216#[non_exhaustive]
217#[derive(Clone, Default, Debug)]
218pub struct ListIncidentTypesOptionalParams {
219    /// Include deleted incident types in the response.
220    pub include_deleted: Option<bool>,
221}
222
223impl ListIncidentTypesOptionalParams {
224    /// Include deleted incident types in the response.
225    pub fn include_deleted(mut self, value: bool) -> Self {
226        self.include_deleted = Some(value);
227        self
228    }
229}
230
231/// ListIncidentsOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::list_incidents`]
232#[non_exhaustive]
233#[derive(Clone, Default, Debug)]
234pub struct ListIncidentsOptionalParams {
235    /// Specifies which types of related objects should be included in the response.
236    pub include: Option<Vec<crate::datadogV2::model::IncidentRelatedObject>>,
237    /// Size for a given page. The maximum allowed value is 100.
238    pub page_size: Option<i64>,
239    /// Specific offset to use as the beginning of the returned page.
240    pub page_offset: Option<i64>,
241}
242
243impl ListIncidentsOptionalParams {
244    /// Specifies which types of related objects should be included in the response.
245    pub fn include(mut self, value: Vec<crate::datadogV2::model::IncidentRelatedObject>) -> Self {
246        self.include = Some(value);
247        self
248    }
249    /// Size for a given page. The maximum allowed value is 100.
250    pub fn page_size(mut self, value: i64) -> Self {
251        self.page_size = Some(value);
252        self
253    }
254    /// Specific offset to use as the beginning of the returned page.
255    pub fn page_offset(mut self, value: i64) -> Self {
256        self.page_offset = Some(value);
257        self
258    }
259}
260
261/// SearchIncidentsOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::search_incidents`]
262#[non_exhaustive]
263#[derive(Clone, Default, Debug)]
264pub struct SearchIncidentsOptionalParams {
265    /// Specifies which types of related objects should be included in the response.
266    pub include: Option<crate::datadogV2::model::IncidentRelatedObject>,
267    /// Specifies the order of returned incidents.
268    pub sort: Option<crate::datadogV2::model::IncidentSearchSortOrder>,
269    /// Size for a given page. The maximum allowed value is 100.
270    pub page_size: Option<i64>,
271    /// Specific offset to use as the beginning of the returned page.
272    pub page_offset: Option<i64>,
273}
274
275impl SearchIncidentsOptionalParams {
276    /// Specifies which types of related objects should be included in the response.
277    pub fn include(mut self, value: crate::datadogV2::model::IncidentRelatedObject) -> Self {
278        self.include = Some(value);
279        self
280    }
281    /// Specifies the order of returned incidents.
282    pub fn sort(mut self, value: crate::datadogV2::model::IncidentSearchSortOrder) -> Self {
283        self.sort = Some(value);
284        self
285    }
286    /// Size for a given page. The maximum allowed value is 100.
287    pub fn page_size(mut self, value: i64) -> Self {
288        self.page_size = Some(value);
289        self
290    }
291    /// Specific offset to use as the beginning of the returned page.
292    pub fn page_offset(mut self, value: i64) -> Self {
293        self.page_offset = Some(value);
294        self
295    }
296}
297
298/// UpdateIncidentOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::update_incident`]
299#[non_exhaustive]
300#[derive(Clone, Default, Debug)]
301pub struct UpdateIncidentOptionalParams {
302    /// Specifies which types of related objects should be included in the response.
303    pub include: Option<Vec<crate::datadogV2::model::IncidentRelatedObject>>,
304}
305
306impl UpdateIncidentOptionalParams {
307    /// Specifies which types of related objects should be included in the response.
308    pub fn include(mut self, value: Vec<crate::datadogV2::model::IncidentRelatedObject>) -> Self {
309        self.include = Some(value);
310        self
311    }
312}
313
314/// UpdateIncidentAttachmentsOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::update_incident_attachments`]
315#[non_exhaustive]
316#[derive(Clone, Default, Debug)]
317pub struct UpdateIncidentAttachmentsOptionalParams {
318    /// Specifies which types of related objects are included in the response.
319    pub include: Option<Vec<crate::datadogV2::model::IncidentAttachmentRelatedObject>>,
320}
321
322impl UpdateIncidentAttachmentsOptionalParams {
323    /// Specifies which types of related objects are included in the response.
324    pub fn include(
325        mut self,
326        value: Vec<crate::datadogV2::model::IncidentAttachmentRelatedObject>,
327    ) -> Self {
328        self.include = Some(value);
329        self
330    }
331}
332
333/// UpdateIncidentNotificationRuleOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::update_incident_notification_rule`]
334#[non_exhaustive]
335#[derive(Clone, Default, Debug)]
336pub struct UpdateIncidentNotificationRuleOptionalParams {
337    /// Comma-separated list of resources to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`, `notification_template`
338    ///
339    pub include: Option<String>,
340}
341
342impl UpdateIncidentNotificationRuleOptionalParams {
343    /// Comma-separated list of resources to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`, `notification_template`
344    ///
345    pub fn include(mut self, value: String) -> Self {
346        self.include = Some(value);
347        self
348    }
349}
350
351/// UpdateIncidentNotificationTemplateOptionalParams is a struct for passing parameters to the method [`IncidentsAPI::update_incident_notification_template`]
352#[non_exhaustive]
353#[derive(Clone, Default, Debug)]
354pub struct UpdateIncidentNotificationTemplateOptionalParams {
355    /// Comma-separated list of relationships to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`
356    ///
357    pub include: Option<String>,
358}
359
360impl UpdateIncidentNotificationTemplateOptionalParams {
361    /// Comma-separated list of relationships to include. Supported values: `created_by_user`, `last_modified_by_user`, `incident_type`
362    ///
363    pub fn include(mut self, value: String) -> Self {
364        self.include = Some(value);
365        self
366    }
367}
368
369/// CreateIncidentError is a struct for typed errors of method [`IncidentsAPI::create_incident`]
370#[derive(Debug, Clone, Serialize, Deserialize)]
371#[serde(untagged)]
372pub enum CreateIncidentError {
373    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
374    UnknownValue(serde_json::Value),
375}
376
377/// CreateIncidentImpactError is a struct for typed errors of method [`IncidentsAPI::create_incident_impact`]
378#[derive(Debug, Clone, Serialize, Deserialize)]
379#[serde(untagged)]
380pub enum CreateIncidentImpactError {
381    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
382    UnknownValue(serde_json::Value),
383}
384
385/// CreateIncidentIntegrationError is a struct for typed errors of method [`IncidentsAPI::create_incident_integration`]
386#[derive(Debug, Clone, Serialize, Deserialize)]
387#[serde(untagged)]
388pub enum CreateIncidentIntegrationError {
389    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
390    UnknownValue(serde_json::Value),
391}
392
393/// CreateIncidentNotificationRuleError is a struct for typed errors of method [`IncidentsAPI::create_incident_notification_rule`]
394#[derive(Debug, Clone, Serialize, Deserialize)]
395#[serde(untagged)]
396pub enum CreateIncidentNotificationRuleError {
397    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
398    UnknownValue(serde_json::Value),
399}
400
401/// CreateIncidentNotificationTemplateError is a struct for typed errors of method [`IncidentsAPI::create_incident_notification_template`]
402#[derive(Debug, Clone, Serialize, Deserialize)]
403#[serde(untagged)]
404pub enum CreateIncidentNotificationTemplateError {
405    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
406    UnknownValue(serde_json::Value),
407}
408
409/// CreateIncidentTodoError is a struct for typed errors of method [`IncidentsAPI::create_incident_todo`]
410#[derive(Debug, Clone, Serialize, Deserialize)]
411#[serde(untagged)]
412pub enum CreateIncidentTodoError {
413    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
414    UnknownValue(serde_json::Value),
415}
416
417/// CreateIncidentTypeError is a struct for typed errors of method [`IncidentsAPI::create_incident_type`]
418#[derive(Debug, Clone, Serialize, Deserialize)]
419#[serde(untagged)]
420pub enum CreateIncidentTypeError {
421    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
422    UnknownValue(serde_json::Value),
423}
424
425/// DeleteIncidentError is a struct for typed errors of method [`IncidentsAPI::delete_incident`]
426#[derive(Debug, Clone, Serialize, Deserialize)]
427#[serde(untagged)]
428pub enum DeleteIncidentError {
429    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
430    UnknownValue(serde_json::Value),
431}
432
433/// DeleteIncidentImpactError is a struct for typed errors of method [`IncidentsAPI::delete_incident_impact`]
434#[derive(Debug, Clone, Serialize, Deserialize)]
435#[serde(untagged)]
436pub enum DeleteIncidentImpactError {
437    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
438    UnknownValue(serde_json::Value),
439}
440
441/// DeleteIncidentIntegrationError is a struct for typed errors of method [`IncidentsAPI::delete_incident_integration`]
442#[derive(Debug, Clone, Serialize, Deserialize)]
443#[serde(untagged)]
444pub enum DeleteIncidentIntegrationError {
445    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
446    UnknownValue(serde_json::Value),
447}
448
449/// DeleteIncidentNotificationRuleError is a struct for typed errors of method [`IncidentsAPI::delete_incident_notification_rule`]
450#[derive(Debug, Clone, Serialize, Deserialize)]
451#[serde(untagged)]
452pub enum DeleteIncidentNotificationRuleError {
453    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
454    UnknownValue(serde_json::Value),
455}
456
457/// DeleteIncidentNotificationTemplateError is a struct for typed errors of method [`IncidentsAPI::delete_incident_notification_template`]
458#[derive(Debug, Clone, Serialize, Deserialize)]
459#[serde(untagged)]
460pub enum DeleteIncidentNotificationTemplateError {
461    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
462    UnknownValue(serde_json::Value),
463}
464
465/// DeleteIncidentTodoError is a struct for typed errors of method [`IncidentsAPI::delete_incident_todo`]
466#[derive(Debug, Clone, Serialize, Deserialize)]
467#[serde(untagged)]
468pub enum DeleteIncidentTodoError {
469    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
470    UnknownValue(serde_json::Value),
471}
472
473/// DeleteIncidentTypeError is a struct for typed errors of method [`IncidentsAPI::delete_incident_type`]
474#[derive(Debug, Clone, Serialize, Deserialize)]
475#[serde(untagged)]
476pub enum DeleteIncidentTypeError {
477    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
478    UnknownValue(serde_json::Value),
479}
480
481/// GetIncidentError is a struct for typed errors of method [`IncidentsAPI::get_incident`]
482#[derive(Debug, Clone, Serialize, Deserialize)]
483#[serde(untagged)]
484pub enum GetIncidentError {
485    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
486    UnknownValue(serde_json::Value),
487}
488
489/// GetIncidentIntegrationError is a struct for typed errors of method [`IncidentsAPI::get_incident_integration`]
490#[derive(Debug, Clone, Serialize, Deserialize)]
491#[serde(untagged)]
492pub enum GetIncidentIntegrationError {
493    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
494    UnknownValue(serde_json::Value),
495}
496
497/// GetIncidentNotificationRuleError is a struct for typed errors of method [`IncidentsAPI::get_incident_notification_rule`]
498#[derive(Debug, Clone, Serialize, Deserialize)]
499#[serde(untagged)]
500pub enum GetIncidentNotificationRuleError {
501    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
502    UnknownValue(serde_json::Value),
503}
504
505/// GetIncidentNotificationTemplateError is a struct for typed errors of method [`IncidentsAPI::get_incident_notification_template`]
506#[derive(Debug, Clone, Serialize, Deserialize)]
507#[serde(untagged)]
508pub enum GetIncidentNotificationTemplateError {
509    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
510    UnknownValue(serde_json::Value),
511}
512
513/// GetIncidentTodoError is a struct for typed errors of method [`IncidentsAPI::get_incident_todo`]
514#[derive(Debug, Clone, Serialize, Deserialize)]
515#[serde(untagged)]
516pub enum GetIncidentTodoError {
517    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
518    UnknownValue(serde_json::Value),
519}
520
521/// GetIncidentTypeError is a struct for typed errors of method [`IncidentsAPI::get_incident_type`]
522#[derive(Debug, Clone, Serialize, Deserialize)]
523#[serde(untagged)]
524pub enum GetIncidentTypeError {
525    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
526    UnknownValue(serde_json::Value),
527}
528
529/// ListIncidentAttachmentsError is a struct for typed errors of method [`IncidentsAPI::list_incident_attachments`]
530#[derive(Debug, Clone, Serialize, Deserialize)]
531#[serde(untagged)]
532pub enum ListIncidentAttachmentsError {
533    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
534    UnknownValue(serde_json::Value),
535}
536
537/// ListIncidentImpactsError is a struct for typed errors of method [`IncidentsAPI::list_incident_impacts`]
538#[derive(Debug, Clone, Serialize, Deserialize)]
539#[serde(untagged)]
540pub enum ListIncidentImpactsError {
541    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
542    UnknownValue(serde_json::Value),
543}
544
545/// ListIncidentIntegrationsError is a struct for typed errors of method [`IncidentsAPI::list_incident_integrations`]
546#[derive(Debug, Clone, Serialize, Deserialize)]
547#[serde(untagged)]
548pub enum ListIncidentIntegrationsError {
549    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
550    UnknownValue(serde_json::Value),
551}
552
553/// ListIncidentNotificationRulesError is a struct for typed errors of method [`IncidentsAPI::list_incident_notification_rules`]
554#[derive(Debug, Clone, Serialize, Deserialize)]
555#[serde(untagged)]
556pub enum ListIncidentNotificationRulesError {
557    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
558    UnknownValue(serde_json::Value),
559}
560
561/// ListIncidentNotificationTemplatesError is a struct for typed errors of method [`IncidentsAPI::list_incident_notification_templates`]
562#[derive(Debug, Clone, Serialize, Deserialize)]
563#[serde(untagged)]
564pub enum ListIncidentNotificationTemplatesError {
565    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
566    UnknownValue(serde_json::Value),
567}
568
569/// ListIncidentTodosError is a struct for typed errors of method [`IncidentsAPI::list_incident_todos`]
570#[derive(Debug, Clone, Serialize, Deserialize)]
571#[serde(untagged)]
572pub enum ListIncidentTodosError {
573    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
574    UnknownValue(serde_json::Value),
575}
576
577/// ListIncidentTypesError is a struct for typed errors of method [`IncidentsAPI::list_incident_types`]
578#[derive(Debug, Clone, Serialize, Deserialize)]
579#[serde(untagged)]
580pub enum ListIncidentTypesError {
581    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
582    UnknownValue(serde_json::Value),
583}
584
585/// ListIncidentsError is a struct for typed errors of method [`IncidentsAPI::list_incidents`]
586#[derive(Debug, Clone, Serialize, Deserialize)]
587#[serde(untagged)]
588pub enum ListIncidentsError {
589    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
590    UnknownValue(serde_json::Value),
591}
592
593/// SearchIncidentsError is a struct for typed errors of method [`IncidentsAPI::search_incidents`]
594#[derive(Debug, Clone, Serialize, Deserialize)]
595#[serde(untagged)]
596pub enum SearchIncidentsError {
597    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
598    UnknownValue(serde_json::Value),
599}
600
601/// UpdateIncidentError is a struct for typed errors of method [`IncidentsAPI::update_incident`]
602#[derive(Debug, Clone, Serialize, Deserialize)]
603#[serde(untagged)]
604pub enum UpdateIncidentError {
605    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
606    UnknownValue(serde_json::Value),
607}
608
609/// UpdateIncidentAttachmentsError is a struct for typed errors of method [`IncidentsAPI::update_incident_attachments`]
610#[derive(Debug, Clone, Serialize, Deserialize)]
611#[serde(untagged)]
612pub enum UpdateIncidentAttachmentsError {
613    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
614    UnknownValue(serde_json::Value),
615}
616
617/// UpdateIncidentIntegrationError is a struct for typed errors of method [`IncidentsAPI::update_incident_integration`]
618#[derive(Debug, Clone, Serialize, Deserialize)]
619#[serde(untagged)]
620pub enum UpdateIncidentIntegrationError {
621    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
622    UnknownValue(serde_json::Value),
623}
624
625/// UpdateIncidentNotificationRuleError is a struct for typed errors of method [`IncidentsAPI::update_incident_notification_rule`]
626#[derive(Debug, Clone, Serialize, Deserialize)]
627#[serde(untagged)]
628pub enum UpdateIncidentNotificationRuleError {
629    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
630    UnknownValue(serde_json::Value),
631}
632
633/// UpdateIncidentNotificationTemplateError is a struct for typed errors of method [`IncidentsAPI::update_incident_notification_template`]
634#[derive(Debug, Clone, Serialize, Deserialize)]
635#[serde(untagged)]
636pub enum UpdateIncidentNotificationTemplateError {
637    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
638    UnknownValue(serde_json::Value),
639}
640
641/// UpdateIncidentTodoError is a struct for typed errors of method [`IncidentsAPI::update_incident_todo`]
642#[derive(Debug, Clone, Serialize, Deserialize)]
643#[serde(untagged)]
644pub enum UpdateIncidentTodoError {
645    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
646    UnknownValue(serde_json::Value),
647}
648
649/// UpdateIncidentTypeError is a struct for typed errors of method [`IncidentsAPI::update_incident_type`]
650#[derive(Debug, Clone, Serialize, Deserialize)]
651#[serde(untagged)]
652pub enum UpdateIncidentTypeError {
653    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
654    UnknownValue(serde_json::Value),
655}
656
657/// Manage incident response, as well as associated attachments, metadata, and todos. See the [Incident Management page](<https://docs.datadoghq.com/service_management/incident_management/>) for more information.
658#[derive(Debug, Clone)]
659pub struct IncidentsAPI {
660    config: datadog::Configuration,
661    client: reqwest_middleware::ClientWithMiddleware,
662}
663
664impl Default for IncidentsAPI {
665    fn default() -> Self {
666        Self::with_config(datadog::Configuration::default())
667    }
668}
669
670impl IncidentsAPI {
671    pub fn new() -> Self {
672        Self::default()
673    }
674    pub fn with_config(config: datadog::Configuration) -> Self {
675        let mut reqwest_client_builder = reqwest::Client::builder();
676
677        if let Some(proxy_url) = &config.proxy_url {
678            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
679            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
680        }
681
682        let mut middleware_client_builder =
683            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
684
685        if config.enable_retry {
686            struct RetryableStatus;
687            impl reqwest_retry::RetryableStrategy for RetryableStatus {
688                fn handle(
689                    &self,
690                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
691                ) -> Option<reqwest_retry::Retryable> {
692                    match res {
693                        Ok(success) => reqwest_retry::default_on_request_success(success),
694                        Err(_) => None,
695                    }
696                }
697            }
698            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
699                .build_with_max_retries(config.max_retries);
700
701            let retry_middleware =
702                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
703                    backoff_policy,
704                    RetryableStatus,
705                );
706
707            middleware_client_builder = middleware_client_builder.with(retry_middleware);
708        }
709
710        let client = middleware_client_builder.build();
711
712        Self { config, client }
713    }
714
715    pub fn with_client_and_config(
716        config: datadog::Configuration,
717        client: reqwest_middleware::ClientWithMiddleware,
718    ) -> Self {
719        Self { config, client }
720    }
721
722    /// Create an incident.
723    pub async fn create_incident(
724        &self,
725        body: crate::datadogV2::model::IncidentCreateRequest,
726    ) -> Result<crate::datadogV2::model::IncidentResponse, datadog::Error<CreateIncidentError>>
727    {
728        match self.create_incident_with_http_info(body).await {
729            Ok(response_content) => {
730                if let Some(e) = response_content.entity {
731                    Ok(e)
732                } else {
733                    Err(datadog::Error::Serde(serde::de::Error::custom(
734                        "response content was None",
735                    )))
736                }
737            }
738            Err(err) => Err(err),
739        }
740    }
741
742    /// Create an incident.
743    pub async fn create_incident_with_http_info(
744        &self,
745        body: crate::datadogV2::model::IncidentCreateRequest,
746    ) -> Result<
747        datadog::ResponseContent<crate::datadogV2::model::IncidentResponse>,
748        datadog::Error<CreateIncidentError>,
749    > {
750        let local_configuration = &self.config;
751        let operation_id = "v2.create_incident";
752        if local_configuration.is_unstable_operation_enabled(operation_id) {
753            warn!("Using unstable operation {operation_id}");
754        } else {
755            let local_error = datadog::UnstableOperationDisabledError {
756                msg: "Operation 'v2.create_incident' is not enabled".to_string(),
757            };
758            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
759        }
760
761        let local_client = &self.client;
762
763        let local_uri_str = format!(
764            "{}/api/v2/incidents",
765            local_configuration.get_operation_host(operation_id)
766        );
767        let mut local_req_builder =
768            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
769
770        // build headers
771        let mut headers = HeaderMap::new();
772        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
773        headers.insert("Accept", HeaderValue::from_static("application/json"));
774
775        // build user agent
776        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
777            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
778            Err(e) => {
779                log::warn!("Failed to parse user agent header: {e}, falling back to default");
780                headers.insert(
781                    reqwest::header::USER_AGENT,
782                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
783                )
784            }
785        };
786
787        // build auth
788        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
789            headers.insert(
790                "DD-API-KEY",
791                HeaderValue::from_str(local_key.key.as_str())
792                    .expect("failed to parse DD-API-KEY header"),
793            );
794        };
795        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
796            headers.insert(
797                "DD-APPLICATION-KEY",
798                HeaderValue::from_str(local_key.key.as_str())
799                    .expect("failed to parse DD-APPLICATION-KEY header"),
800            );
801        };
802
803        // build body parameters
804        let output = Vec::new();
805        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
806        if body.serialize(&mut ser).is_ok() {
807            if let Some(content_encoding) = headers.get("Content-Encoding") {
808                match content_encoding.to_str().unwrap_or_default() {
809                    "gzip" => {
810                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
811                        let _ = enc.write_all(ser.into_inner().as_slice());
812                        match enc.finish() {
813                            Ok(buf) => {
814                                local_req_builder = local_req_builder.body(buf);
815                            }
816                            Err(e) => return Err(datadog::Error::Io(e)),
817                        }
818                    }
819                    "deflate" => {
820                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
821                        let _ = enc.write_all(ser.into_inner().as_slice());
822                        match enc.finish() {
823                            Ok(buf) => {
824                                local_req_builder = local_req_builder.body(buf);
825                            }
826                            Err(e) => return Err(datadog::Error::Io(e)),
827                        }
828                    }
829                    "zstd1" => {
830                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
831                        let _ = enc.write_all(ser.into_inner().as_slice());
832                        match enc.finish() {
833                            Ok(buf) => {
834                                local_req_builder = local_req_builder.body(buf);
835                            }
836                            Err(e) => return Err(datadog::Error::Io(e)),
837                        }
838                    }
839                    _ => {
840                        local_req_builder = local_req_builder.body(ser.into_inner());
841                    }
842                }
843            } else {
844                local_req_builder = local_req_builder.body(ser.into_inner());
845            }
846        }
847
848        local_req_builder = local_req_builder.headers(headers);
849        let local_req = local_req_builder.build()?;
850        log::debug!("request content: {:?}", local_req.body());
851        let local_resp = local_client.execute(local_req).await?;
852
853        let local_status = local_resp.status();
854        let local_content = local_resp.text().await?;
855        log::debug!("response content: {}", local_content);
856
857        if !local_status.is_client_error() && !local_status.is_server_error() {
858            match serde_json::from_str::<crate::datadogV2::model::IncidentResponse>(&local_content)
859            {
860                Ok(e) => {
861                    return Ok(datadog::ResponseContent {
862                        status: local_status,
863                        content: local_content,
864                        entity: Some(e),
865                    })
866                }
867                Err(e) => return Err(datadog::Error::Serde(e)),
868            };
869        } else {
870            let local_entity: Option<CreateIncidentError> =
871                serde_json::from_str(&local_content).ok();
872            let local_error = datadog::ResponseContent {
873                status: local_status,
874                content: local_content,
875                entity: local_entity,
876            };
877            Err(datadog::Error::ResponseError(local_error))
878        }
879    }
880
881    /// Create an impact for an incident.
882    pub async fn create_incident_impact(
883        &self,
884        incident_id: String,
885        body: crate::datadogV2::model::IncidentImpactCreateRequest,
886        params: CreateIncidentImpactOptionalParams,
887    ) -> Result<
888        crate::datadogV2::model::IncidentImpactResponse,
889        datadog::Error<CreateIncidentImpactError>,
890    > {
891        match self
892            .create_incident_impact_with_http_info(incident_id, body, params)
893            .await
894        {
895            Ok(response_content) => {
896                if let Some(e) = response_content.entity {
897                    Ok(e)
898                } else {
899                    Err(datadog::Error::Serde(serde::de::Error::custom(
900                        "response content was None",
901                    )))
902                }
903            }
904            Err(err) => Err(err),
905        }
906    }
907
908    /// Create an impact for an incident.
909    pub async fn create_incident_impact_with_http_info(
910        &self,
911        incident_id: String,
912        body: crate::datadogV2::model::IncidentImpactCreateRequest,
913        params: CreateIncidentImpactOptionalParams,
914    ) -> Result<
915        datadog::ResponseContent<crate::datadogV2::model::IncidentImpactResponse>,
916        datadog::Error<CreateIncidentImpactError>,
917    > {
918        let local_configuration = &self.config;
919        let operation_id = "v2.create_incident_impact";
920        if local_configuration.is_unstable_operation_enabled(operation_id) {
921            warn!("Using unstable operation {operation_id}");
922        } else {
923            let local_error = datadog::UnstableOperationDisabledError {
924                msg: "Operation 'v2.create_incident_impact' is not enabled".to_string(),
925            };
926            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
927        }
928
929        // unbox and build optional parameters
930        let include = params.include;
931
932        let local_client = &self.client;
933
934        let local_uri_str = format!(
935            "{}/api/v2/incidents/{incident_id}/impacts",
936            local_configuration.get_operation_host(operation_id),
937            incident_id = datadog::urlencode(incident_id)
938        );
939        let mut local_req_builder =
940            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
941
942        if let Some(ref local) = include {
943            local_req_builder = local_req_builder.query(&[(
944                "include",
945                &local
946                    .iter()
947                    .map(|p| p.to_string())
948                    .collect::<Vec<String>>()
949                    .join(",")
950                    .to_string(),
951            )]);
952        };
953
954        // build headers
955        let mut headers = HeaderMap::new();
956        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
957        headers.insert("Accept", HeaderValue::from_static("application/json"));
958
959        // build user agent
960        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
961            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
962            Err(e) => {
963                log::warn!("Failed to parse user agent header: {e}, falling back to default");
964                headers.insert(
965                    reqwest::header::USER_AGENT,
966                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
967                )
968            }
969        };
970
971        // build auth
972        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
973            headers.insert(
974                "DD-API-KEY",
975                HeaderValue::from_str(local_key.key.as_str())
976                    .expect("failed to parse DD-API-KEY header"),
977            );
978        };
979        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
980            headers.insert(
981                "DD-APPLICATION-KEY",
982                HeaderValue::from_str(local_key.key.as_str())
983                    .expect("failed to parse DD-APPLICATION-KEY header"),
984            );
985        };
986
987        // build body parameters
988        let output = Vec::new();
989        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
990        if body.serialize(&mut ser).is_ok() {
991            if let Some(content_encoding) = headers.get("Content-Encoding") {
992                match content_encoding.to_str().unwrap_or_default() {
993                    "gzip" => {
994                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
995                        let _ = enc.write_all(ser.into_inner().as_slice());
996                        match enc.finish() {
997                            Ok(buf) => {
998                                local_req_builder = local_req_builder.body(buf);
999                            }
1000                            Err(e) => return Err(datadog::Error::Io(e)),
1001                        }
1002                    }
1003                    "deflate" => {
1004                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1005                        let _ = enc.write_all(ser.into_inner().as_slice());
1006                        match enc.finish() {
1007                            Ok(buf) => {
1008                                local_req_builder = local_req_builder.body(buf);
1009                            }
1010                            Err(e) => return Err(datadog::Error::Io(e)),
1011                        }
1012                    }
1013                    "zstd1" => {
1014                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1015                        let _ = enc.write_all(ser.into_inner().as_slice());
1016                        match enc.finish() {
1017                            Ok(buf) => {
1018                                local_req_builder = local_req_builder.body(buf);
1019                            }
1020                            Err(e) => return Err(datadog::Error::Io(e)),
1021                        }
1022                    }
1023                    _ => {
1024                        local_req_builder = local_req_builder.body(ser.into_inner());
1025                    }
1026                }
1027            } else {
1028                local_req_builder = local_req_builder.body(ser.into_inner());
1029            }
1030        }
1031
1032        local_req_builder = local_req_builder.headers(headers);
1033        let local_req = local_req_builder.build()?;
1034        log::debug!("request content: {:?}", local_req.body());
1035        let local_resp = local_client.execute(local_req).await?;
1036
1037        let local_status = local_resp.status();
1038        let local_content = local_resp.text().await?;
1039        log::debug!("response content: {}", local_content);
1040
1041        if !local_status.is_client_error() && !local_status.is_server_error() {
1042            match serde_json::from_str::<crate::datadogV2::model::IncidentImpactResponse>(
1043                &local_content,
1044            ) {
1045                Ok(e) => {
1046                    return Ok(datadog::ResponseContent {
1047                        status: local_status,
1048                        content: local_content,
1049                        entity: Some(e),
1050                    })
1051                }
1052                Err(e) => return Err(datadog::Error::Serde(e)),
1053            };
1054        } else {
1055            let local_entity: Option<CreateIncidentImpactError> =
1056                serde_json::from_str(&local_content).ok();
1057            let local_error = datadog::ResponseContent {
1058                status: local_status,
1059                content: local_content,
1060                entity: local_entity,
1061            };
1062            Err(datadog::Error::ResponseError(local_error))
1063        }
1064    }
1065
1066    /// Create an incident integration metadata.
1067    pub async fn create_incident_integration(
1068        &self,
1069        incident_id: String,
1070        body: crate::datadogV2::model::IncidentIntegrationMetadataCreateRequest,
1071    ) -> Result<
1072        crate::datadogV2::model::IncidentIntegrationMetadataResponse,
1073        datadog::Error<CreateIncidentIntegrationError>,
1074    > {
1075        match self
1076            .create_incident_integration_with_http_info(incident_id, body)
1077            .await
1078        {
1079            Ok(response_content) => {
1080                if let Some(e) = response_content.entity {
1081                    Ok(e)
1082                } else {
1083                    Err(datadog::Error::Serde(serde::de::Error::custom(
1084                        "response content was None",
1085                    )))
1086                }
1087            }
1088            Err(err) => Err(err),
1089        }
1090    }
1091
1092    /// Create an incident integration metadata.
1093    pub async fn create_incident_integration_with_http_info(
1094        &self,
1095        incident_id: String,
1096        body: crate::datadogV2::model::IncidentIntegrationMetadataCreateRequest,
1097    ) -> Result<
1098        datadog::ResponseContent<crate::datadogV2::model::IncidentIntegrationMetadataResponse>,
1099        datadog::Error<CreateIncidentIntegrationError>,
1100    > {
1101        let local_configuration = &self.config;
1102        let operation_id = "v2.create_incident_integration";
1103        if local_configuration.is_unstable_operation_enabled(operation_id) {
1104            warn!("Using unstable operation {operation_id}");
1105        } else {
1106            let local_error = datadog::UnstableOperationDisabledError {
1107                msg: "Operation 'v2.create_incident_integration' is not enabled".to_string(),
1108            };
1109            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1110        }
1111
1112        let local_client = &self.client;
1113
1114        let local_uri_str = format!(
1115            "{}/api/v2/incidents/{incident_id}/relationships/integrations",
1116            local_configuration.get_operation_host(operation_id),
1117            incident_id = datadog::urlencode(incident_id)
1118        );
1119        let mut local_req_builder =
1120            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1121
1122        // build headers
1123        let mut headers = HeaderMap::new();
1124        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1125        headers.insert("Accept", HeaderValue::from_static("application/json"));
1126
1127        // build user agent
1128        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1129            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1130            Err(e) => {
1131                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1132                headers.insert(
1133                    reqwest::header::USER_AGENT,
1134                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1135                )
1136            }
1137        };
1138
1139        // build auth
1140        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1141            headers.insert(
1142                "DD-API-KEY",
1143                HeaderValue::from_str(local_key.key.as_str())
1144                    .expect("failed to parse DD-API-KEY header"),
1145            );
1146        };
1147        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1148            headers.insert(
1149                "DD-APPLICATION-KEY",
1150                HeaderValue::from_str(local_key.key.as_str())
1151                    .expect("failed to parse DD-APPLICATION-KEY header"),
1152            );
1153        };
1154
1155        // build body parameters
1156        let output = Vec::new();
1157        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1158        if body.serialize(&mut ser).is_ok() {
1159            if let Some(content_encoding) = headers.get("Content-Encoding") {
1160                match content_encoding.to_str().unwrap_or_default() {
1161                    "gzip" => {
1162                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1163                        let _ = enc.write_all(ser.into_inner().as_slice());
1164                        match enc.finish() {
1165                            Ok(buf) => {
1166                                local_req_builder = local_req_builder.body(buf);
1167                            }
1168                            Err(e) => return Err(datadog::Error::Io(e)),
1169                        }
1170                    }
1171                    "deflate" => {
1172                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1173                        let _ = enc.write_all(ser.into_inner().as_slice());
1174                        match enc.finish() {
1175                            Ok(buf) => {
1176                                local_req_builder = local_req_builder.body(buf);
1177                            }
1178                            Err(e) => return Err(datadog::Error::Io(e)),
1179                        }
1180                    }
1181                    "zstd1" => {
1182                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1183                        let _ = enc.write_all(ser.into_inner().as_slice());
1184                        match enc.finish() {
1185                            Ok(buf) => {
1186                                local_req_builder = local_req_builder.body(buf);
1187                            }
1188                            Err(e) => return Err(datadog::Error::Io(e)),
1189                        }
1190                    }
1191                    _ => {
1192                        local_req_builder = local_req_builder.body(ser.into_inner());
1193                    }
1194                }
1195            } else {
1196                local_req_builder = local_req_builder.body(ser.into_inner());
1197            }
1198        }
1199
1200        local_req_builder = local_req_builder.headers(headers);
1201        let local_req = local_req_builder.build()?;
1202        log::debug!("request content: {:?}", local_req.body());
1203        let local_resp = local_client.execute(local_req).await?;
1204
1205        let local_status = local_resp.status();
1206        let local_content = local_resp.text().await?;
1207        log::debug!("response content: {}", local_content);
1208
1209        if !local_status.is_client_error() && !local_status.is_server_error() {
1210            match serde_json::from_str::<crate::datadogV2::model::IncidentIntegrationMetadataResponse>(
1211                &local_content,
1212            ) {
1213                Ok(e) => {
1214                    return Ok(datadog::ResponseContent {
1215                        status: local_status,
1216                        content: local_content,
1217                        entity: Some(e),
1218                    })
1219                }
1220                Err(e) => return Err(datadog::Error::Serde(e)),
1221            };
1222        } else {
1223            let local_entity: Option<CreateIncidentIntegrationError> =
1224                serde_json::from_str(&local_content).ok();
1225            let local_error = datadog::ResponseContent {
1226                status: local_status,
1227                content: local_content,
1228                entity: local_entity,
1229            };
1230            Err(datadog::Error::ResponseError(local_error))
1231        }
1232    }
1233
1234    /// Creates a new notification rule.
1235    pub async fn create_incident_notification_rule(
1236        &self,
1237        body: crate::datadogV2::model::CreateIncidentNotificationRuleRequest,
1238    ) -> Result<
1239        crate::datadogV2::model::IncidentNotificationRule,
1240        datadog::Error<CreateIncidentNotificationRuleError>,
1241    > {
1242        match self
1243            .create_incident_notification_rule_with_http_info(body)
1244            .await
1245        {
1246            Ok(response_content) => {
1247                if let Some(e) = response_content.entity {
1248                    Ok(e)
1249                } else {
1250                    Err(datadog::Error::Serde(serde::de::Error::custom(
1251                        "response content was None",
1252                    )))
1253                }
1254            }
1255            Err(err) => Err(err),
1256        }
1257    }
1258
1259    /// Creates a new notification rule.
1260    pub async fn create_incident_notification_rule_with_http_info(
1261        &self,
1262        body: crate::datadogV2::model::CreateIncidentNotificationRuleRequest,
1263    ) -> Result<
1264        datadog::ResponseContent<crate::datadogV2::model::IncidentNotificationRule>,
1265        datadog::Error<CreateIncidentNotificationRuleError>,
1266    > {
1267        let local_configuration = &self.config;
1268        let operation_id = "v2.create_incident_notification_rule";
1269        if local_configuration.is_unstable_operation_enabled(operation_id) {
1270            warn!("Using unstable operation {operation_id}");
1271        } else {
1272            let local_error = datadog::UnstableOperationDisabledError {
1273                msg: "Operation 'v2.create_incident_notification_rule' is not enabled".to_string(),
1274            };
1275            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1276        }
1277
1278        let local_client = &self.client;
1279
1280        let local_uri_str = format!(
1281            "{}/api/v2/incidents/config/notification-rules",
1282            local_configuration.get_operation_host(operation_id)
1283        );
1284        let mut local_req_builder =
1285            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1286
1287        // build headers
1288        let mut headers = HeaderMap::new();
1289        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1290        headers.insert("Accept", HeaderValue::from_static("application/json"));
1291
1292        // build user agent
1293        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1294            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1295            Err(e) => {
1296                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1297                headers.insert(
1298                    reqwest::header::USER_AGENT,
1299                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1300                )
1301            }
1302        };
1303
1304        // build auth
1305        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1306            headers.insert(
1307                "DD-API-KEY",
1308                HeaderValue::from_str(local_key.key.as_str())
1309                    .expect("failed to parse DD-API-KEY header"),
1310            );
1311        };
1312        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1313            headers.insert(
1314                "DD-APPLICATION-KEY",
1315                HeaderValue::from_str(local_key.key.as_str())
1316                    .expect("failed to parse DD-APPLICATION-KEY header"),
1317            );
1318        };
1319
1320        // build body parameters
1321        let output = Vec::new();
1322        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1323        if body.serialize(&mut ser).is_ok() {
1324            if let Some(content_encoding) = headers.get("Content-Encoding") {
1325                match content_encoding.to_str().unwrap_or_default() {
1326                    "gzip" => {
1327                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1328                        let _ = enc.write_all(ser.into_inner().as_slice());
1329                        match enc.finish() {
1330                            Ok(buf) => {
1331                                local_req_builder = local_req_builder.body(buf);
1332                            }
1333                            Err(e) => return Err(datadog::Error::Io(e)),
1334                        }
1335                    }
1336                    "deflate" => {
1337                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1338                        let _ = enc.write_all(ser.into_inner().as_slice());
1339                        match enc.finish() {
1340                            Ok(buf) => {
1341                                local_req_builder = local_req_builder.body(buf);
1342                            }
1343                            Err(e) => return Err(datadog::Error::Io(e)),
1344                        }
1345                    }
1346                    "zstd1" => {
1347                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1348                        let _ = enc.write_all(ser.into_inner().as_slice());
1349                        match enc.finish() {
1350                            Ok(buf) => {
1351                                local_req_builder = local_req_builder.body(buf);
1352                            }
1353                            Err(e) => return Err(datadog::Error::Io(e)),
1354                        }
1355                    }
1356                    _ => {
1357                        local_req_builder = local_req_builder.body(ser.into_inner());
1358                    }
1359                }
1360            } else {
1361                local_req_builder = local_req_builder.body(ser.into_inner());
1362            }
1363        }
1364
1365        local_req_builder = local_req_builder.headers(headers);
1366        let local_req = local_req_builder.build()?;
1367        log::debug!("request content: {:?}", local_req.body());
1368        let local_resp = local_client.execute(local_req).await?;
1369
1370        let local_status = local_resp.status();
1371        let local_content = local_resp.text().await?;
1372        log::debug!("response content: {}", local_content);
1373
1374        if !local_status.is_client_error() && !local_status.is_server_error() {
1375            match serde_json::from_str::<crate::datadogV2::model::IncidentNotificationRule>(
1376                &local_content,
1377            ) {
1378                Ok(e) => {
1379                    return Ok(datadog::ResponseContent {
1380                        status: local_status,
1381                        content: local_content,
1382                        entity: Some(e),
1383                    })
1384                }
1385                Err(e) => return Err(datadog::Error::Serde(e)),
1386            };
1387        } else {
1388            let local_entity: Option<CreateIncidentNotificationRuleError> =
1389                serde_json::from_str(&local_content).ok();
1390            let local_error = datadog::ResponseContent {
1391                status: local_status,
1392                content: local_content,
1393                entity: local_entity,
1394            };
1395            Err(datadog::Error::ResponseError(local_error))
1396        }
1397    }
1398
1399    /// Creates a new notification template.
1400    pub async fn create_incident_notification_template(
1401        &self,
1402        body: crate::datadogV2::model::CreateIncidentNotificationTemplateRequest,
1403    ) -> Result<
1404        crate::datadogV2::model::IncidentNotificationTemplate,
1405        datadog::Error<CreateIncidentNotificationTemplateError>,
1406    > {
1407        match self
1408            .create_incident_notification_template_with_http_info(body)
1409            .await
1410        {
1411            Ok(response_content) => {
1412                if let Some(e) = response_content.entity {
1413                    Ok(e)
1414                } else {
1415                    Err(datadog::Error::Serde(serde::de::Error::custom(
1416                        "response content was None",
1417                    )))
1418                }
1419            }
1420            Err(err) => Err(err),
1421        }
1422    }
1423
1424    /// Creates a new notification template.
1425    pub async fn create_incident_notification_template_with_http_info(
1426        &self,
1427        body: crate::datadogV2::model::CreateIncidentNotificationTemplateRequest,
1428    ) -> Result<
1429        datadog::ResponseContent<crate::datadogV2::model::IncidentNotificationTemplate>,
1430        datadog::Error<CreateIncidentNotificationTemplateError>,
1431    > {
1432        let local_configuration = &self.config;
1433        let operation_id = "v2.create_incident_notification_template";
1434        if local_configuration.is_unstable_operation_enabled(operation_id) {
1435            warn!("Using unstable operation {operation_id}");
1436        } else {
1437            let local_error = datadog::UnstableOperationDisabledError {
1438                msg: "Operation 'v2.create_incident_notification_template' is not enabled"
1439                    .to_string(),
1440            };
1441            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1442        }
1443
1444        let local_client = &self.client;
1445
1446        let local_uri_str = format!(
1447            "{}/api/v2/incidents/config/notification-templates",
1448            local_configuration.get_operation_host(operation_id)
1449        );
1450        let mut local_req_builder =
1451            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1452
1453        // build headers
1454        let mut headers = HeaderMap::new();
1455        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1456        headers.insert("Accept", HeaderValue::from_static("application/json"));
1457
1458        // build user agent
1459        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1460            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1461            Err(e) => {
1462                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1463                headers.insert(
1464                    reqwest::header::USER_AGENT,
1465                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1466                )
1467            }
1468        };
1469
1470        // build auth
1471        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1472            headers.insert(
1473                "DD-API-KEY",
1474                HeaderValue::from_str(local_key.key.as_str())
1475                    .expect("failed to parse DD-API-KEY header"),
1476            );
1477        };
1478        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1479            headers.insert(
1480                "DD-APPLICATION-KEY",
1481                HeaderValue::from_str(local_key.key.as_str())
1482                    .expect("failed to parse DD-APPLICATION-KEY header"),
1483            );
1484        };
1485
1486        // build body parameters
1487        let output = Vec::new();
1488        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1489        if body.serialize(&mut ser).is_ok() {
1490            if let Some(content_encoding) = headers.get("Content-Encoding") {
1491                match content_encoding.to_str().unwrap_or_default() {
1492                    "gzip" => {
1493                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1494                        let _ = enc.write_all(ser.into_inner().as_slice());
1495                        match enc.finish() {
1496                            Ok(buf) => {
1497                                local_req_builder = local_req_builder.body(buf);
1498                            }
1499                            Err(e) => return Err(datadog::Error::Io(e)),
1500                        }
1501                    }
1502                    "deflate" => {
1503                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1504                        let _ = enc.write_all(ser.into_inner().as_slice());
1505                        match enc.finish() {
1506                            Ok(buf) => {
1507                                local_req_builder = local_req_builder.body(buf);
1508                            }
1509                            Err(e) => return Err(datadog::Error::Io(e)),
1510                        }
1511                    }
1512                    "zstd1" => {
1513                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1514                        let _ = enc.write_all(ser.into_inner().as_slice());
1515                        match enc.finish() {
1516                            Ok(buf) => {
1517                                local_req_builder = local_req_builder.body(buf);
1518                            }
1519                            Err(e) => return Err(datadog::Error::Io(e)),
1520                        }
1521                    }
1522                    _ => {
1523                        local_req_builder = local_req_builder.body(ser.into_inner());
1524                    }
1525                }
1526            } else {
1527                local_req_builder = local_req_builder.body(ser.into_inner());
1528            }
1529        }
1530
1531        local_req_builder = local_req_builder.headers(headers);
1532        let local_req = local_req_builder.build()?;
1533        log::debug!("request content: {:?}", local_req.body());
1534        let local_resp = local_client.execute(local_req).await?;
1535
1536        let local_status = local_resp.status();
1537        let local_content = local_resp.text().await?;
1538        log::debug!("response content: {}", local_content);
1539
1540        if !local_status.is_client_error() && !local_status.is_server_error() {
1541            match serde_json::from_str::<crate::datadogV2::model::IncidentNotificationTemplate>(
1542                &local_content,
1543            ) {
1544                Ok(e) => {
1545                    return Ok(datadog::ResponseContent {
1546                        status: local_status,
1547                        content: local_content,
1548                        entity: Some(e),
1549                    })
1550                }
1551                Err(e) => return Err(datadog::Error::Serde(e)),
1552            };
1553        } else {
1554            let local_entity: Option<CreateIncidentNotificationTemplateError> =
1555                serde_json::from_str(&local_content).ok();
1556            let local_error = datadog::ResponseContent {
1557                status: local_status,
1558                content: local_content,
1559                entity: local_entity,
1560            };
1561            Err(datadog::Error::ResponseError(local_error))
1562        }
1563    }
1564
1565    /// Create an incident todo.
1566    pub async fn create_incident_todo(
1567        &self,
1568        incident_id: String,
1569        body: crate::datadogV2::model::IncidentTodoCreateRequest,
1570    ) -> Result<
1571        crate::datadogV2::model::IncidentTodoResponse,
1572        datadog::Error<CreateIncidentTodoError>,
1573    > {
1574        match self
1575            .create_incident_todo_with_http_info(incident_id, body)
1576            .await
1577        {
1578            Ok(response_content) => {
1579                if let Some(e) = response_content.entity {
1580                    Ok(e)
1581                } else {
1582                    Err(datadog::Error::Serde(serde::de::Error::custom(
1583                        "response content was None",
1584                    )))
1585                }
1586            }
1587            Err(err) => Err(err),
1588        }
1589    }
1590
1591    /// Create an incident todo.
1592    pub async fn create_incident_todo_with_http_info(
1593        &self,
1594        incident_id: String,
1595        body: crate::datadogV2::model::IncidentTodoCreateRequest,
1596    ) -> Result<
1597        datadog::ResponseContent<crate::datadogV2::model::IncidentTodoResponse>,
1598        datadog::Error<CreateIncidentTodoError>,
1599    > {
1600        let local_configuration = &self.config;
1601        let operation_id = "v2.create_incident_todo";
1602        if local_configuration.is_unstable_operation_enabled(operation_id) {
1603            warn!("Using unstable operation {operation_id}");
1604        } else {
1605            let local_error = datadog::UnstableOperationDisabledError {
1606                msg: "Operation 'v2.create_incident_todo' is not enabled".to_string(),
1607            };
1608            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1609        }
1610
1611        let local_client = &self.client;
1612
1613        let local_uri_str = format!(
1614            "{}/api/v2/incidents/{incident_id}/relationships/todos",
1615            local_configuration.get_operation_host(operation_id),
1616            incident_id = datadog::urlencode(incident_id)
1617        );
1618        let mut local_req_builder =
1619            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1620
1621        // build headers
1622        let mut headers = HeaderMap::new();
1623        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1624        headers.insert("Accept", HeaderValue::from_static("application/json"));
1625
1626        // build user agent
1627        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1628            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1629            Err(e) => {
1630                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1631                headers.insert(
1632                    reqwest::header::USER_AGENT,
1633                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1634                )
1635            }
1636        };
1637
1638        // build auth
1639        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1640            headers.insert(
1641                "DD-API-KEY",
1642                HeaderValue::from_str(local_key.key.as_str())
1643                    .expect("failed to parse DD-API-KEY header"),
1644            );
1645        };
1646        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1647            headers.insert(
1648                "DD-APPLICATION-KEY",
1649                HeaderValue::from_str(local_key.key.as_str())
1650                    .expect("failed to parse DD-APPLICATION-KEY header"),
1651            );
1652        };
1653
1654        // build body parameters
1655        let output = Vec::new();
1656        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1657        if body.serialize(&mut ser).is_ok() {
1658            if let Some(content_encoding) = headers.get("Content-Encoding") {
1659                match content_encoding.to_str().unwrap_or_default() {
1660                    "gzip" => {
1661                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1662                        let _ = enc.write_all(ser.into_inner().as_slice());
1663                        match enc.finish() {
1664                            Ok(buf) => {
1665                                local_req_builder = local_req_builder.body(buf);
1666                            }
1667                            Err(e) => return Err(datadog::Error::Io(e)),
1668                        }
1669                    }
1670                    "deflate" => {
1671                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1672                        let _ = enc.write_all(ser.into_inner().as_slice());
1673                        match enc.finish() {
1674                            Ok(buf) => {
1675                                local_req_builder = local_req_builder.body(buf);
1676                            }
1677                            Err(e) => return Err(datadog::Error::Io(e)),
1678                        }
1679                    }
1680                    "zstd1" => {
1681                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1682                        let _ = enc.write_all(ser.into_inner().as_slice());
1683                        match enc.finish() {
1684                            Ok(buf) => {
1685                                local_req_builder = local_req_builder.body(buf);
1686                            }
1687                            Err(e) => return Err(datadog::Error::Io(e)),
1688                        }
1689                    }
1690                    _ => {
1691                        local_req_builder = local_req_builder.body(ser.into_inner());
1692                    }
1693                }
1694            } else {
1695                local_req_builder = local_req_builder.body(ser.into_inner());
1696            }
1697        }
1698
1699        local_req_builder = local_req_builder.headers(headers);
1700        let local_req = local_req_builder.build()?;
1701        log::debug!("request content: {:?}", local_req.body());
1702        let local_resp = local_client.execute(local_req).await?;
1703
1704        let local_status = local_resp.status();
1705        let local_content = local_resp.text().await?;
1706        log::debug!("response content: {}", local_content);
1707
1708        if !local_status.is_client_error() && !local_status.is_server_error() {
1709            match serde_json::from_str::<crate::datadogV2::model::IncidentTodoResponse>(
1710                &local_content,
1711            ) {
1712                Ok(e) => {
1713                    return Ok(datadog::ResponseContent {
1714                        status: local_status,
1715                        content: local_content,
1716                        entity: Some(e),
1717                    })
1718                }
1719                Err(e) => return Err(datadog::Error::Serde(e)),
1720            };
1721        } else {
1722            let local_entity: Option<CreateIncidentTodoError> =
1723                serde_json::from_str(&local_content).ok();
1724            let local_error = datadog::ResponseContent {
1725                status: local_status,
1726                content: local_content,
1727                entity: local_entity,
1728            };
1729            Err(datadog::Error::ResponseError(local_error))
1730        }
1731    }
1732
1733    /// Create an incident type.
1734    pub async fn create_incident_type(
1735        &self,
1736        body: crate::datadogV2::model::IncidentTypeCreateRequest,
1737    ) -> Result<
1738        crate::datadogV2::model::IncidentTypeResponse,
1739        datadog::Error<CreateIncidentTypeError>,
1740    > {
1741        match self.create_incident_type_with_http_info(body).await {
1742            Ok(response_content) => {
1743                if let Some(e) = response_content.entity {
1744                    Ok(e)
1745                } else {
1746                    Err(datadog::Error::Serde(serde::de::Error::custom(
1747                        "response content was None",
1748                    )))
1749                }
1750            }
1751            Err(err) => Err(err),
1752        }
1753    }
1754
1755    /// Create an incident type.
1756    pub async fn create_incident_type_with_http_info(
1757        &self,
1758        body: crate::datadogV2::model::IncidentTypeCreateRequest,
1759    ) -> Result<
1760        datadog::ResponseContent<crate::datadogV2::model::IncidentTypeResponse>,
1761        datadog::Error<CreateIncidentTypeError>,
1762    > {
1763        let local_configuration = &self.config;
1764        let operation_id = "v2.create_incident_type";
1765        if local_configuration.is_unstable_operation_enabled(operation_id) {
1766            warn!("Using unstable operation {operation_id}");
1767        } else {
1768            let local_error = datadog::UnstableOperationDisabledError {
1769                msg: "Operation 'v2.create_incident_type' is not enabled".to_string(),
1770            };
1771            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1772        }
1773
1774        let local_client = &self.client;
1775
1776        let local_uri_str = format!(
1777            "{}/api/v2/incidents/config/types",
1778            local_configuration.get_operation_host(operation_id)
1779        );
1780        let mut local_req_builder =
1781            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1782
1783        // build headers
1784        let mut headers = HeaderMap::new();
1785        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1786        headers.insert("Accept", HeaderValue::from_static("application/json"));
1787
1788        // build user agent
1789        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1790            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1791            Err(e) => {
1792                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1793                headers.insert(
1794                    reqwest::header::USER_AGENT,
1795                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1796                )
1797            }
1798        };
1799
1800        // build auth
1801        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1802            headers.insert(
1803                "DD-API-KEY",
1804                HeaderValue::from_str(local_key.key.as_str())
1805                    .expect("failed to parse DD-API-KEY header"),
1806            );
1807        };
1808        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1809            headers.insert(
1810                "DD-APPLICATION-KEY",
1811                HeaderValue::from_str(local_key.key.as_str())
1812                    .expect("failed to parse DD-APPLICATION-KEY header"),
1813            );
1814        };
1815
1816        // build body parameters
1817        let output = Vec::new();
1818        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1819        if body.serialize(&mut ser).is_ok() {
1820            if let Some(content_encoding) = headers.get("Content-Encoding") {
1821                match content_encoding.to_str().unwrap_or_default() {
1822                    "gzip" => {
1823                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1824                        let _ = enc.write_all(ser.into_inner().as_slice());
1825                        match enc.finish() {
1826                            Ok(buf) => {
1827                                local_req_builder = local_req_builder.body(buf);
1828                            }
1829                            Err(e) => return Err(datadog::Error::Io(e)),
1830                        }
1831                    }
1832                    "deflate" => {
1833                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1834                        let _ = enc.write_all(ser.into_inner().as_slice());
1835                        match enc.finish() {
1836                            Ok(buf) => {
1837                                local_req_builder = local_req_builder.body(buf);
1838                            }
1839                            Err(e) => return Err(datadog::Error::Io(e)),
1840                        }
1841                    }
1842                    "zstd1" => {
1843                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1844                        let _ = enc.write_all(ser.into_inner().as_slice());
1845                        match enc.finish() {
1846                            Ok(buf) => {
1847                                local_req_builder = local_req_builder.body(buf);
1848                            }
1849                            Err(e) => return Err(datadog::Error::Io(e)),
1850                        }
1851                    }
1852                    _ => {
1853                        local_req_builder = local_req_builder.body(ser.into_inner());
1854                    }
1855                }
1856            } else {
1857                local_req_builder = local_req_builder.body(ser.into_inner());
1858            }
1859        }
1860
1861        local_req_builder = local_req_builder.headers(headers);
1862        let local_req = local_req_builder.build()?;
1863        log::debug!("request content: {:?}", local_req.body());
1864        let local_resp = local_client.execute(local_req).await?;
1865
1866        let local_status = local_resp.status();
1867        let local_content = local_resp.text().await?;
1868        log::debug!("response content: {}", local_content);
1869
1870        if !local_status.is_client_error() && !local_status.is_server_error() {
1871            match serde_json::from_str::<crate::datadogV2::model::IncidentTypeResponse>(
1872                &local_content,
1873            ) {
1874                Ok(e) => {
1875                    return Ok(datadog::ResponseContent {
1876                        status: local_status,
1877                        content: local_content,
1878                        entity: Some(e),
1879                    })
1880                }
1881                Err(e) => return Err(datadog::Error::Serde(e)),
1882            };
1883        } else {
1884            let local_entity: Option<CreateIncidentTypeError> =
1885                serde_json::from_str(&local_content).ok();
1886            let local_error = datadog::ResponseContent {
1887                status: local_status,
1888                content: local_content,
1889                entity: local_entity,
1890            };
1891            Err(datadog::Error::ResponseError(local_error))
1892        }
1893    }
1894
1895    /// Deletes an existing incident from the users organization.
1896    pub async fn delete_incident(
1897        &self,
1898        incident_id: String,
1899    ) -> Result<(), datadog::Error<DeleteIncidentError>> {
1900        match self.delete_incident_with_http_info(incident_id).await {
1901            Ok(_) => Ok(()),
1902            Err(err) => Err(err),
1903        }
1904    }
1905
1906    /// Deletes an existing incident from the users organization.
1907    pub async fn delete_incident_with_http_info(
1908        &self,
1909        incident_id: String,
1910    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentError>> {
1911        let local_configuration = &self.config;
1912        let operation_id = "v2.delete_incident";
1913        if local_configuration.is_unstable_operation_enabled(operation_id) {
1914            warn!("Using unstable operation {operation_id}");
1915        } else {
1916            let local_error = datadog::UnstableOperationDisabledError {
1917                msg: "Operation 'v2.delete_incident' is not enabled".to_string(),
1918            };
1919            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1920        }
1921
1922        let local_client = &self.client;
1923
1924        let local_uri_str = format!(
1925            "{}/api/v2/incidents/{incident_id}",
1926            local_configuration.get_operation_host(operation_id),
1927            incident_id = datadog::urlencode(incident_id)
1928        );
1929        let mut local_req_builder =
1930            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1931
1932        // build headers
1933        let mut headers = HeaderMap::new();
1934        headers.insert("Accept", HeaderValue::from_static("*/*"));
1935
1936        // build user agent
1937        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1938            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1939            Err(e) => {
1940                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1941                headers.insert(
1942                    reqwest::header::USER_AGENT,
1943                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1944                )
1945            }
1946        };
1947
1948        // build auth
1949        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1950            headers.insert(
1951                "DD-API-KEY",
1952                HeaderValue::from_str(local_key.key.as_str())
1953                    .expect("failed to parse DD-API-KEY header"),
1954            );
1955        };
1956        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1957            headers.insert(
1958                "DD-APPLICATION-KEY",
1959                HeaderValue::from_str(local_key.key.as_str())
1960                    .expect("failed to parse DD-APPLICATION-KEY header"),
1961            );
1962        };
1963
1964        local_req_builder = local_req_builder.headers(headers);
1965        let local_req = local_req_builder.build()?;
1966        log::debug!("request content: {:?}", local_req.body());
1967        let local_resp = local_client.execute(local_req).await?;
1968
1969        let local_status = local_resp.status();
1970        let local_content = local_resp.text().await?;
1971        log::debug!("response content: {}", local_content);
1972
1973        if !local_status.is_client_error() && !local_status.is_server_error() {
1974            Ok(datadog::ResponseContent {
1975                status: local_status,
1976                content: local_content,
1977                entity: None,
1978            })
1979        } else {
1980            let local_entity: Option<DeleteIncidentError> =
1981                serde_json::from_str(&local_content).ok();
1982            let local_error = datadog::ResponseContent {
1983                status: local_status,
1984                content: local_content,
1985                entity: local_entity,
1986            };
1987            Err(datadog::Error::ResponseError(local_error))
1988        }
1989    }
1990
1991    /// Delete an incident impact.
1992    pub async fn delete_incident_impact(
1993        &self,
1994        incident_id: String,
1995        impact_id: String,
1996    ) -> Result<(), datadog::Error<DeleteIncidentImpactError>> {
1997        match self
1998            .delete_incident_impact_with_http_info(incident_id, impact_id)
1999            .await
2000        {
2001            Ok(_) => Ok(()),
2002            Err(err) => Err(err),
2003        }
2004    }
2005
2006    /// Delete an incident impact.
2007    pub async fn delete_incident_impact_with_http_info(
2008        &self,
2009        incident_id: String,
2010        impact_id: String,
2011    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentImpactError>> {
2012        let local_configuration = &self.config;
2013        let operation_id = "v2.delete_incident_impact";
2014        if local_configuration.is_unstable_operation_enabled(operation_id) {
2015            warn!("Using unstable operation {operation_id}");
2016        } else {
2017            let local_error = datadog::UnstableOperationDisabledError {
2018                msg: "Operation 'v2.delete_incident_impact' is not enabled".to_string(),
2019            };
2020            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2021        }
2022
2023        let local_client = &self.client;
2024
2025        let local_uri_str = format!(
2026            "{}/api/v2/incidents/{incident_id}/impacts/{impact_id}",
2027            local_configuration.get_operation_host(operation_id),
2028            incident_id = datadog::urlencode(incident_id),
2029            impact_id = datadog::urlencode(impact_id)
2030        );
2031        let mut local_req_builder =
2032            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
2033
2034        // build headers
2035        let mut headers = HeaderMap::new();
2036        headers.insert("Accept", HeaderValue::from_static("*/*"));
2037
2038        // build user agent
2039        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2040            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2041            Err(e) => {
2042                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2043                headers.insert(
2044                    reqwest::header::USER_AGENT,
2045                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2046                )
2047            }
2048        };
2049
2050        // build auth
2051        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2052            headers.insert(
2053                "DD-API-KEY",
2054                HeaderValue::from_str(local_key.key.as_str())
2055                    .expect("failed to parse DD-API-KEY header"),
2056            );
2057        };
2058        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2059            headers.insert(
2060                "DD-APPLICATION-KEY",
2061                HeaderValue::from_str(local_key.key.as_str())
2062                    .expect("failed to parse DD-APPLICATION-KEY header"),
2063            );
2064        };
2065
2066        local_req_builder = local_req_builder.headers(headers);
2067        let local_req = local_req_builder.build()?;
2068        log::debug!("request content: {:?}", local_req.body());
2069        let local_resp = local_client.execute(local_req).await?;
2070
2071        let local_status = local_resp.status();
2072        let local_content = local_resp.text().await?;
2073        log::debug!("response content: {}", local_content);
2074
2075        if !local_status.is_client_error() && !local_status.is_server_error() {
2076            Ok(datadog::ResponseContent {
2077                status: local_status,
2078                content: local_content,
2079                entity: None,
2080            })
2081        } else {
2082            let local_entity: Option<DeleteIncidentImpactError> =
2083                serde_json::from_str(&local_content).ok();
2084            let local_error = datadog::ResponseContent {
2085                status: local_status,
2086                content: local_content,
2087                entity: local_entity,
2088            };
2089            Err(datadog::Error::ResponseError(local_error))
2090        }
2091    }
2092
2093    /// Delete an incident integration metadata.
2094    pub async fn delete_incident_integration(
2095        &self,
2096        incident_id: String,
2097        integration_metadata_id: String,
2098    ) -> Result<(), datadog::Error<DeleteIncidentIntegrationError>> {
2099        match self
2100            .delete_incident_integration_with_http_info(incident_id, integration_metadata_id)
2101            .await
2102        {
2103            Ok(_) => Ok(()),
2104            Err(err) => Err(err),
2105        }
2106    }
2107
2108    /// Delete an incident integration metadata.
2109    pub async fn delete_incident_integration_with_http_info(
2110        &self,
2111        incident_id: String,
2112        integration_metadata_id: String,
2113    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentIntegrationError>> {
2114        let local_configuration = &self.config;
2115        let operation_id = "v2.delete_incident_integration";
2116        if local_configuration.is_unstable_operation_enabled(operation_id) {
2117            warn!("Using unstable operation {operation_id}");
2118        } else {
2119            let local_error = datadog::UnstableOperationDisabledError {
2120                msg: "Operation 'v2.delete_incident_integration' is not enabled".to_string(),
2121            };
2122            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2123        }
2124
2125        let local_client = &self.client;
2126
2127        let local_uri_str = format!(
2128            "{}/api/v2/incidents/{incident_id}/relationships/integrations/{integration_metadata_id}",
2129            local_configuration.get_operation_host(operation_id), incident_id=
2130            datadog::urlencode(incident_id)
2131            , integration_metadata_id=
2132            datadog::urlencode(integration_metadata_id)
2133            );
2134        let mut local_req_builder =
2135            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
2136
2137        // build headers
2138        let mut headers = HeaderMap::new();
2139        headers.insert("Accept", HeaderValue::from_static("*/*"));
2140
2141        // build user agent
2142        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2143            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2144            Err(e) => {
2145                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2146                headers.insert(
2147                    reqwest::header::USER_AGENT,
2148                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2149                )
2150            }
2151        };
2152
2153        // build auth
2154        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2155            headers.insert(
2156                "DD-API-KEY",
2157                HeaderValue::from_str(local_key.key.as_str())
2158                    .expect("failed to parse DD-API-KEY header"),
2159            );
2160        };
2161        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2162            headers.insert(
2163                "DD-APPLICATION-KEY",
2164                HeaderValue::from_str(local_key.key.as_str())
2165                    .expect("failed to parse DD-APPLICATION-KEY header"),
2166            );
2167        };
2168
2169        local_req_builder = local_req_builder.headers(headers);
2170        let local_req = local_req_builder.build()?;
2171        log::debug!("request content: {:?}", local_req.body());
2172        let local_resp = local_client.execute(local_req).await?;
2173
2174        let local_status = local_resp.status();
2175        let local_content = local_resp.text().await?;
2176        log::debug!("response content: {}", local_content);
2177
2178        if !local_status.is_client_error() && !local_status.is_server_error() {
2179            Ok(datadog::ResponseContent {
2180                status: local_status,
2181                content: local_content,
2182                entity: None,
2183            })
2184        } else {
2185            let local_entity: Option<DeleteIncidentIntegrationError> =
2186                serde_json::from_str(&local_content).ok();
2187            let local_error = datadog::ResponseContent {
2188                status: local_status,
2189                content: local_content,
2190                entity: local_entity,
2191            };
2192            Err(datadog::Error::ResponseError(local_error))
2193        }
2194    }
2195
2196    /// Deletes a notification rule by its ID.
2197    pub async fn delete_incident_notification_rule(
2198        &self,
2199        id: uuid::Uuid,
2200        params: DeleteIncidentNotificationRuleOptionalParams,
2201    ) -> Result<(), datadog::Error<DeleteIncidentNotificationRuleError>> {
2202        match self
2203            .delete_incident_notification_rule_with_http_info(id, params)
2204            .await
2205        {
2206            Ok(_) => Ok(()),
2207            Err(err) => Err(err),
2208        }
2209    }
2210
2211    /// Deletes a notification rule by its ID.
2212    pub async fn delete_incident_notification_rule_with_http_info(
2213        &self,
2214        id: uuid::Uuid,
2215        params: DeleteIncidentNotificationRuleOptionalParams,
2216    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentNotificationRuleError>>
2217    {
2218        let local_configuration = &self.config;
2219        let operation_id = "v2.delete_incident_notification_rule";
2220        if local_configuration.is_unstable_operation_enabled(operation_id) {
2221            warn!("Using unstable operation {operation_id}");
2222        } else {
2223            let local_error = datadog::UnstableOperationDisabledError {
2224                msg: "Operation 'v2.delete_incident_notification_rule' is not enabled".to_string(),
2225            };
2226            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2227        }
2228
2229        // unbox and build optional parameters
2230        let include = params.include;
2231
2232        let local_client = &self.client;
2233
2234        let local_uri_str = format!(
2235            "{}/api/v2/incidents/config/notification-rules/{id}",
2236            local_configuration.get_operation_host(operation_id),
2237            id = datadog::urlencode(id.to_string())
2238        );
2239        let mut local_req_builder =
2240            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
2241
2242        if let Some(ref local_query_param) = include {
2243            local_req_builder =
2244                local_req_builder.query(&[("include", &local_query_param.to_string())]);
2245        };
2246
2247        // build headers
2248        let mut headers = HeaderMap::new();
2249        headers.insert("Accept", HeaderValue::from_static("*/*"));
2250
2251        // build user agent
2252        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2253            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2254            Err(e) => {
2255                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2256                headers.insert(
2257                    reqwest::header::USER_AGENT,
2258                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2259                )
2260            }
2261        };
2262
2263        // build auth
2264        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2265            headers.insert(
2266                "DD-API-KEY",
2267                HeaderValue::from_str(local_key.key.as_str())
2268                    .expect("failed to parse DD-API-KEY header"),
2269            );
2270        };
2271        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2272            headers.insert(
2273                "DD-APPLICATION-KEY",
2274                HeaderValue::from_str(local_key.key.as_str())
2275                    .expect("failed to parse DD-APPLICATION-KEY header"),
2276            );
2277        };
2278
2279        local_req_builder = local_req_builder.headers(headers);
2280        let local_req = local_req_builder.build()?;
2281        log::debug!("request content: {:?}", local_req.body());
2282        let local_resp = local_client.execute(local_req).await?;
2283
2284        let local_status = local_resp.status();
2285        let local_content = local_resp.text().await?;
2286        log::debug!("response content: {}", local_content);
2287
2288        if !local_status.is_client_error() && !local_status.is_server_error() {
2289            Ok(datadog::ResponseContent {
2290                status: local_status,
2291                content: local_content,
2292                entity: None,
2293            })
2294        } else {
2295            let local_entity: Option<DeleteIncidentNotificationRuleError> =
2296                serde_json::from_str(&local_content).ok();
2297            let local_error = datadog::ResponseContent {
2298                status: local_status,
2299                content: local_content,
2300                entity: local_entity,
2301            };
2302            Err(datadog::Error::ResponseError(local_error))
2303        }
2304    }
2305
2306    /// Deletes a notification template by its ID.
2307    pub async fn delete_incident_notification_template(
2308        &self,
2309        id: uuid::Uuid,
2310        params: DeleteIncidentNotificationTemplateOptionalParams,
2311    ) -> Result<(), datadog::Error<DeleteIncidentNotificationTemplateError>> {
2312        match self
2313            .delete_incident_notification_template_with_http_info(id, params)
2314            .await
2315        {
2316            Ok(_) => Ok(()),
2317            Err(err) => Err(err),
2318        }
2319    }
2320
2321    /// Deletes a notification template by its ID.
2322    pub async fn delete_incident_notification_template_with_http_info(
2323        &self,
2324        id: uuid::Uuid,
2325        params: DeleteIncidentNotificationTemplateOptionalParams,
2326    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentNotificationTemplateError>>
2327    {
2328        let local_configuration = &self.config;
2329        let operation_id = "v2.delete_incident_notification_template";
2330        if local_configuration.is_unstable_operation_enabled(operation_id) {
2331            warn!("Using unstable operation {operation_id}");
2332        } else {
2333            let local_error = datadog::UnstableOperationDisabledError {
2334                msg: "Operation 'v2.delete_incident_notification_template' is not enabled"
2335                    .to_string(),
2336            };
2337            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2338        }
2339
2340        // unbox and build optional parameters
2341        let include = params.include;
2342
2343        let local_client = &self.client;
2344
2345        let local_uri_str = format!(
2346            "{}/api/v2/incidents/config/notification-templates/{id}",
2347            local_configuration.get_operation_host(operation_id),
2348            id = datadog::urlencode(id.to_string())
2349        );
2350        let mut local_req_builder =
2351            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
2352
2353        if let Some(ref local_query_param) = include {
2354            local_req_builder =
2355                local_req_builder.query(&[("include", &local_query_param.to_string())]);
2356        };
2357
2358        // build headers
2359        let mut headers = HeaderMap::new();
2360        headers.insert("Accept", HeaderValue::from_static("*/*"));
2361
2362        // build user agent
2363        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2364            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2365            Err(e) => {
2366                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2367                headers.insert(
2368                    reqwest::header::USER_AGENT,
2369                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2370                )
2371            }
2372        };
2373
2374        // build auth
2375        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2376            headers.insert(
2377                "DD-API-KEY",
2378                HeaderValue::from_str(local_key.key.as_str())
2379                    .expect("failed to parse DD-API-KEY header"),
2380            );
2381        };
2382        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2383            headers.insert(
2384                "DD-APPLICATION-KEY",
2385                HeaderValue::from_str(local_key.key.as_str())
2386                    .expect("failed to parse DD-APPLICATION-KEY header"),
2387            );
2388        };
2389
2390        local_req_builder = local_req_builder.headers(headers);
2391        let local_req = local_req_builder.build()?;
2392        log::debug!("request content: {:?}", local_req.body());
2393        let local_resp = local_client.execute(local_req).await?;
2394
2395        let local_status = local_resp.status();
2396        let local_content = local_resp.text().await?;
2397        log::debug!("response content: {}", local_content);
2398
2399        if !local_status.is_client_error() && !local_status.is_server_error() {
2400            Ok(datadog::ResponseContent {
2401                status: local_status,
2402                content: local_content,
2403                entity: None,
2404            })
2405        } else {
2406            let local_entity: Option<DeleteIncidentNotificationTemplateError> =
2407                serde_json::from_str(&local_content).ok();
2408            let local_error = datadog::ResponseContent {
2409                status: local_status,
2410                content: local_content,
2411                entity: local_entity,
2412            };
2413            Err(datadog::Error::ResponseError(local_error))
2414        }
2415    }
2416
2417    /// Delete an incident todo.
2418    pub async fn delete_incident_todo(
2419        &self,
2420        incident_id: String,
2421        todo_id: String,
2422    ) -> Result<(), datadog::Error<DeleteIncidentTodoError>> {
2423        match self
2424            .delete_incident_todo_with_http_info(incident_id, todo_id)
2425            .await
2426        {
2427            Ok(_) => Ok(()),
2428            Err(err) => Err(err),
2429        }
2430    }
2431
2432    /// Delete an incident todo.
2433    pub async fn delete_incident_todo_with_http_info(
2434        &self,
2435        incident_id: String,
2436        todo_id: String,
2437    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentTodoError>> {
2438        let local_configuration = &self.config;
2439        let operation_id = "v2.delete_incident_todo";
2440        if local_configuration.is_unstable_operation_enabled(operation_id) {
2441            warn!("Using unstable operation {operation_id}");
2442        } else {
2443            let local_error = datadog::UnstableOperationDisabledError {
2444                msg: "Operation 'v2.delete_incident_todo' is not enabled".to_string(),
2445            };
2446            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2447        }
2448
2449        let local_client = &self.client;
2450
2451        let local_uri_str = format!(
2452            "{}/api/v2/incidents/{incident_id}/relationships/todos/{todo_id}",
2453            local_configuration.get_operation_host(operation_id),
2454            incident_id = datadog::urlencode(incident_id),
2455            todo_id = datadog::urlencode(todo_id)
2456        );
2457        let mut local_req_builder =
2458            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
2459
2460        // build headers
2461        let mut headers = HeaderMap::new();
2462        headers.insert("Accept", HeaderValue::from_static("*/*"));
2463
2464        // build user agent
2465        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2466            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2467            Err(e) => {
2468                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2469                headers.insert(
2470                    reqwest::header::USER_AGENT,
2471                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2472                )
2473            }
2474        };
2475
2476        // build auth
2477        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2478            headers.insert(
2479                "DD-API-KEY",
2480                HeaderValue::from_str(local_key.key.as_str())
2481                    .expect("failed to parse DD-API-KEY header"),
2482            );
2483        };
2484        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2485            headers.insert(
2486                "DD-APPLICATION-KEY",
2487                HeaderValue::from_str(local_key.key.as_str())
2488                    .expect("failed to parse DD-APPLICATION-KEY header"),
2489            );
2490        };
2491
2492        local_req_builder = local_req_builder.headers(headers);
2493        let local_req = local_req_builder.build()?;
2494        log::debug!("request content: {:?}", local_req.body());
2495        let local_resp = local_client.execute(local_req).await?;
2496
2497        let local_status = local_resp.status();
2498        let local_content = local_resp.text().await?;
2499        log::debug!("response content: {}", local_content);
2500
2501        if !local_status.is_client_error() && !local_status.is_server_error() {
2502            Ok(datadog::ResponseContent {
2503                status: local_status,
2504                content: local_content,
2505                entity: None,
2506            })
2507        } else {
2508            let local_entity: Option<DeleteIncidentTodoError> =
2509                serde_json::from_str(&local_content).ok();
2510            let local_error = datadog::ResponseContent {
2511                status: local_status,
2512                content: local_content,
2513                entity: local_entity,
2514            };
2515            Err(datadog::Error::ResponseError(local_error))
2516        }
2517    }
2518
2519    /// Delete an incident type.
2520    pub async fn delete_incident_type(
2521        &self,
2522        incident_type_id: String,
2523    ) -> Result<(), datadog::Error<DeleteIncidentTypeError>> {
2524        match self
2525            .delete_incident_type_with_http_info(incident_type_id)
2526            .await
2527        {
2528            Ok(_) => Ok(()),
2529            Err(err) => Err(err),
2530        }
2531    }
2532
2533    /// Delete an incident type.
2534    pub async fn delete_incident_type_with_http_info(
2535        &self,
2536        incident_type_id: String,
2537    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentTypeError>> {
2538        let local_configuration = &self.config;
2539        let operation_id = "v2.delete_incident_type";
2540        if local_configuration.is_unstable_operation_enabled(operation_id) {
2541            warn!("Using unstable operation {operation_id}");
2542        } else {
2543            let local_error = datadog::UnstableOperationDisabledError {
2544                msg: "Operation 'v2.delete_incident_type' is not enabled".to_string(),
2545            };
2546            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2547        }
2548
2549        let local_client = &self.client;
2550
2551        let local_uri_str = format!(
2552            "{}/api/v2/incidents/config/types/{incident_type_id}",
2553            local_configuration.get_operation_host(operation_id),
2554            incident_type_id = datadog::urlencode(incident_type_id)
2555        );
2556        let mut local_req_builder =
2557            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
2558
2559        // build headers
2560        let mut headers = HeaderMap::new();
2561        headers.insert("Accept", HeaderValue::from_static("*/*"));
2562
2563        // build user agent
2564        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2565            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2566            Err(e) => {
2567                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2568                headers.insert(
2569                    reqwest::header::USER_AGENT,
2570                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2571                )
2572            }
2573        };
2574
2575        // build auth
2576        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2577            headers.insert(
2578                "DD-API-KEY",
2579                HeaderValue::from_str(local_key.key.as_str())
2580                    .expect("failed to parse DD-API-KEY header"),
2581            );
2582        };
2583        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2584            headers.insert(
2585                "DD-APPLICATION-KEY",
2586                HeaderValue::from_str(local_key.key.as_str())
2587                    .expect("failed to parse DD-APPLICATION-KEY header"),
2588            );
2589        };
2590
2591        local_req_builder = local_req_builder.headers(headers);
2592        let local_req = local_req_builder.build()?;
2593        log::debug!("request content: {:?}", local_req.body());
2594        let local_resp = local_client.execute(local_req).await?;
2595
2596        let local_status = local_resp.status();
2597        let local_content = local_resp.text().await?;
2598        log::debug!("response content: {}", local_content);
2599
2600        if !local_status.is_client_error() && !local_status.is_server_error() {
2601            Ok(datadog::ResponseContent {
2602                status: local_status,
2603                content: local_content,
2604                entity: None,
2605            })
2606        } else {
2607            let local_entity: Option<DeleteIncidentTypeError> =
2608                serde_json::from_str(&local_content).ok();
2609            let local_error = datadog::ResponseContent {
2610                status: local_status,
2611                content: local_content,
2612                entity: local_entity,
2613            };
2614            Err(datadog::Error::ResponseError(local_error))
2615        }
2616    }
2617
2618    /// Get the details of an incident by `incident_id`.
2619    pub async fn get_incident(
2620        &self,
2621        incident_id: String,
2622        params: GetIncidentOptionalParams,
2623    ) -> Result<crate::datadogV2::model::IncidentResponse, datadog::Error<GetIncidentError>> {
2624        match self.get_incident_with_http_info(incident_id, params).await {
2625            Ok(response_content) => {
2626                if let Some(e) = response_content.entity {
2627                    Ok(e)
2628                } else {
2629                    Err(datadog::Error::Serde(serde::de::Error::custom(
2630                        "response content was None",
2631                    )))
2632                }
2633            }
2634            Err(err) => Err(err),
2635        }
2636    }
2637
2638    /// Get the details of an incident by `incident_id`.
2639    pub async fn get_incident_with_http_info(
2640        &self,
2641        incident_id: String,
2642        params: GetIncidentOptionalParams,
2643    ) -> Result<
2644        datadog::ResponseContent<crate::datadogV2::model::IncidentResponse>,
2645        datadog::Error<GetIncidentError>,
2646    > {
2647        let local_configuration = &self.config;
2648        let operation_id = "v2.get_incident";
2649        if local_configuration.is_unstable_operation_enabled(operation_id) {
2650            warn!("Using unstable operation {operation_id}");
2651        } else {
2652            let local_error = datadog::UnstableOperationDisabledError {
2653                msg: "Operation 'v2.get_incident' is not enabled".to_string(),
2654            };
2655            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2656        }
2657
2658        // unbox and build optional parameters
2659        let include = params.include;
2660
2661        let local_client = &self.client;
2662
2663        let local_uri_str = format!(
2664            "{}/api/v2/incidents/{incident_id}",
2665            local_configuration.get_operation_host(operation_id),
2666            incident_id = datadog::urlencode(incident_id)
2667        );
2668        let mut local_req_builder =
2669            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2670
2671        if let Some(ref local) = include {
2672            local_req_builder = local_req_builder.query(&[(
2673                "include",
2674                &local
2675                    .iter()
2676                    .map(|p| p.to_string())
2677                    .collect::<Vec<String>>()
2678                    .join(",")
2679                    .to_string(),
2680            )]);
2681        };
2682
2683        // build headers
2684        let mut headers = HeaderMap::new();
2685        headers.insert("Accept", HeaderValue::from_static("application/json"));
2686
2687        // build user agent
2688        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2689            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2690            Err(e) => {
2691                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2692                headers.insert(
2693                    reqwest::header::USER_AGENT,
2694                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2695                )
2696            }
2697        };
2698
2699        // build auth
2700        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2701            headers.insert(
2702                "DD-API-KEY",
2703                HeaderValue::from_str(local_key.key.as_str())
2704                    .expect("failed to parse DD-API-KEY header"),
2705            );
2706        };
2707        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2708            headers.insert(
2709                "DD-APPLICATION-KEY",
2710                HeaderValue::from_str(local_key.key.as_str())
2711                    .expect("failed to parse DD-APPLICATION-KEY header"),
2712            );
2713        };
2714
2715        local_req_builder = local_req_builder.headers(headers);
2716        let local_req = local_req_builder.build()?;
2717        log::debug!("request content: {:?}", local_req.body());
2718        let local_resp = local_client.execute(local_req).await?;
2719
2720        let local_status = local_resp.status();
2721        let local_content = local_resp.text().await?;
2722        log::debug!("response content: {}", local_content);
2723
2724        if !local_status.is_client_error() && !local_status.is_server_error() {
2725            match serde_json::from_str::<crate::datadogV2::model::IncidentResponse>(&local_content)
2726            {
2727                Ok(e) => {
2728                    return Ok(datadog::ResponseContent {
2729                        status: local_status,
2730                        content: local_content,
2731                        entity: Some(e),
2732                    })
2733                }
2734                Err(e) => return Err(datadog::Error::Serde(e)),
2735            };
2736        } else {
2737            let local_entity: Option<GetIncidentError> = serde_json::from_str(&local_content).ok();
2738            let local_error = datadog::ResponseContent {
2739                status: local_status,
2740                content: local_content,
2741                entity: local_entity,
2742            };
2743            Err(datadog::Error::ResponseError(local_error))
2744        }
2745    }
2746
2747    /// Get incident integration metadata details.
2748    pub async fn get_incident_integration(
2749        &self,
2750        incident_id: String,
2751        integration_metadata_id: String,
2752    ) -> Result<
2753        crate::datadogV2::model::IncidentIntegrationMetadataResponse,
2754        datadog::Error<GetIncidentIntegrationError>,
2755    > {
2756        match self
2757            .get_incident_integration_with_http_info(incident_id, integration_metadata_id)
2758            .await
2759        {
2760            Ok(response_content) => {
2761                if let Some(e) = response_content.entity {
2762                    Ok(e)
2763                } else {
2764                    Err(datadog::Error::Serde(serde::de::Error::custom(
2765                        "response content was None",
2766                    )))
2767                }
2768            }
2769            Err(err) => Err(err),
2770        }
2771    }
2772
2773    /// Get incident integration metadata details.
2774    pub async fn get_incident_integration_with_http_info(
2775        &self,
2776        incident_id: String,
2777        integration_metadata_id: String,
2778    ) -> Result<
2779        datadog::ResponseContent<crate::datadogV2::model::IncidentIntegrationMetadataResponse>,
2780        datadog::Error<GetIncidentIntegrationError>,
2781    > {
2782        let local_configuration = &self.config;
2783        let operation_id = "v2.get_incident_integration";
2784        if local_configuration.is_unstable_operation_enabled(operation_id) {
2785            warn!("Using unstable operation {operation_id}");
2786        } else {
2787            let local_error = datadog::UnstableOperationDisabledError {
2788                msg: "Operation 'v2.get_incident_integration' is not enabled".to_string(),
2789            };
2790            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2791        }
2792
2793        let local_client = &self.client;
2794
2795        let local_uri_str = format!(
2796            "{}/api/v2/incidents/{incident_id}/relationships/integrations/{integration_metadata_id}",
2797            local_configuration.get_operation_host(operation_id), incident_id=
2798            datadog::urlencode(incident_id)
2799            , integration_metadata_id=
2800            datadog::urlencode(integration_metadata_id)
2801            );
2802        let mut local_req_builder =
2803            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2804
2805        // build headers
2806        let mut headers = HeaderMap::new();
2807        headers.insert("Accept", HeaderValue::from_static("application/json"));
2808
2809        // build user agent
2810        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2811            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2812            Err(e) => {
2813                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2814                headers.insert(
2815                    reqwest::header::USER_AGENT,
2816                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2817                )
2818            }
2819        };
2820
2821        // build auth
2822        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2823            headers.insert(
2824                "DD-API-KEY",
2825                HeaderValue::from_str(local_key.key.as_str())
2826                    .expect("failed to parse DD-API-KEY header"),
2827            );
2828        };
2829        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2830            headers.insert(
2831                "DD-APPLICATION-KEY",
2832                HeaderValue::from_str(local_key.key.as_str())
2833                    .expect("failed to parse DD-APPLICATION-KEY header"),
2834            );
2835        };
2836
2837        local_req_builder = local_req_builder.headers(headers);
2838        let local_req = local_req_builder.build()?;
2839        log::debug!("request content: {:?}", local_req.body());
2840        let local_resp = local_client.execute(local_req).await?;
2841
2842        let local_status = local_resp.status();
2843        let local_content = local_resp.text().await?;
2844        log::debug!("response content: {}", local_content);
2845
2846        if !local_status.is_client_error() && !local_status.is_server_error() {
2847            match serde_json::from_str::<crate::datadogV2::model::IncidentIntegrationMetadataResponse>(
2848                &local_content,
2849            ) {
2850                Ok(e) => {
2851                    return Ok(datadog::ResponseContent {
2852                        status: local_status,
2853                        content: local_content,
2854                        entity: Some(e),
2855                    })
2856                }
2857                Err(e) => return Err(datadog::Error::Serde(e)),
2858            };
2859        } else {
2860            let local_entity: Option<GetIncidentIntegrationError> =
2861                serde_json::from_str(&local_content).ok();
2862            let local_error = datadog::ResponseContent {
2863                status: local_status,
2864                content: local_content,
2865                entity: local_entity,
2866            };
2867            Err(datadog::Error::ResponseError(local_error))
2868        }
2869    }
2870
2871    /// Retrieves a specific notification rule by its ID.
2872    pub async fn get_incident_notification_rule(
2873        &self,
2874        id: uuid::Uuid,
2875        params: GetIncidentNotificationRuleOptionalParams,
2876    ) -> Result<
2877        crate::datadogV2::model::IncidentNotificationRule,
2878        datadog::Error<GetIncidentNotificationRuleError>,
2879    > {
2880        match self
2881            .get_incident_notification_rule_with_http_info(id, params)
2882            .await
2883        {
2884            Ok(response_content) => {
2885                if let Some(e) = response_content.entity {
2886                    Ok(e)
2887                } else {
2888                    Err(datadog::Error::Serde(serde::de::Error::custom(
2889                        "response content was None",
2890                    )))
2891                }
2892            }
2893            Err(err) => Err(err),
2894        }
2895    }
2896
2897    /// Retrieves a specific notification rule by its ID.
2898    pub async fn get_incident_notification_rule_with_http_info(
2899        &self,
2900        id: uuid::Uuid,
2901        params: GetIncidentNotificationRuleOptionalParams,
2902    ) -> Result<
2903        datadog::ResponseContent<crate::datadogV2::model::IncidentNotificationRule>,
2904        datadog::Error<GetIncidentNotificationRuleError>,
2905    > {
2906        let local_configuration = &self.config;
2907        let operation_id = "v2.get_incident_notification_rule";
2908        if local_configuration.is_unstable_operation_enabled(operation_id) {
2909            warn!("Using unstable operation {operation_id}");
2910        } else {
2911            let local_error = datadog::UnstableOperationDisabledError {
2912                msg: "Operation 'v2.get_incident_notification_rule' is not enabled".to_string(),
2913            };
2914            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2915        }
2916
2917        // unbox and build optional parameters
2918        let include = params.include;
2919
2920        let local_client = &self.client;
2921
2922        let local_uri_str = format!(
2923            "{}/api/v2/incidents/config/notification-rules/{id}",
2924            local_configuration.get_operation_host(operation_id),
2925            id = datadog::urlencode(id.to_string())
2926        );
2927        let mut local_req_builder =
2928            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2929
2930        if let Some(ref local_query_param) = include {
2931            local_req_builder =
2932                local_req_builder.query(&[("include", &local_query_param.to_string())]);
2933        };
2934
2935        // build headers
2936        let mut headers = HeaderMap::new();
2937        headers.insert("Accept", HeaderValue::from_static("application/json"));
2938
2939        // build user agent
2940        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2941            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2942            Err(e) => {
2943                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2944                headers.insert(
2945                    reqwest::header::USER_AGENT,
2946                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2947                )
2948            }
2949        };
2950
2951        // build auth
2952        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2953            headers.insert(
2954                "DD-API-KEY",
2955                HeaderValue::from_str(local_key.key.as_str())
2956                    .expect("failed to parse DD-API-KEY header"),
2957            );
2958        };
2959        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2960            headers.insert(
2961                "DD-APPLICATION-KEY",
2962                HeaderValue::from_str(local_key.key.as_str())
2963                    .expect("failed to parse DD-APPLICATION-KEY header"),
2964            );
2965        };
2966
2967        local_req_builder = local_req_builder.headers(headers);
2968        let local_req = local_req_builder.build()?;
2969        log::debug!("request content: {:?}", local_req.body());
2970        let local_resp = local_client.execute(local_req).await?;
2971
2972        let local_status = local_resp.status();
2973        let local_content = local_resp.text().await?;
2974        log::debug!("response content: {}", local_content);
2975
2976        if !local_status.is_client_error() && !local_status.is_server_error() {
2977            match serde_json::from_str::<crate::datadogV2::model::IncidentNotificationRule>(
2978                &local_content,
2979            ) {
2980                Ok(e) => {
2981                    return Ok(datadog::ResponseContent {
2982                        status: local_status,
2983                        content: local_content,
2984                        entity: Some(e),
2985                    })
2986                }
2987                Err(e) => return Err(datadog::Error::Serde(e)),
2988            };
2989        } else {
2990            let local_entity: Option<GetIncidentNotificationRuleError> =
2991                serde_json::from_str(&local_content).ok();
2992            let local_error = datadog::ResponseContent {
2993                status: local_status,
2994                content: local_content,
2995                entity: local_entity,
2996            };
2997            Err(datadog::Error::ResponseError(local_error))
2998        }
2999    }
3000
3001    /// Retrieves a specific notification template by its ID.
3002    pub async fn get_incident_notification_template(
3003        &self,
3004        id: uuid::Uuid,
3005        params: GetIncidentNotificationTemplateOptionalParams,
3006    ) -> Result<
3007        crate::datadogV2::model::IncidentNotificationTemplate,
3008        datadog::Error<GetIncidentNotificationTemplateError>,
3009    > {
3010        match self
3011            .get_incident_notification_template_with_http_info(id, params)
3012            .await
3013        {
3014            Ok(response_content) => {
3015                if let Some(e) = response_content.entity {
3016                    Ok(e)
3017                } else {
3018                    Err(datadog::Error::Serde(serde::de::Error::custom(
3019                        "response content was None",
3020                    )))
3021                }
3022            }
3023            Err(err) => Err(err),
3024        }
3025    }
3026
3027    /// Retrieves a specific notification template by its ID.
3028    pub async fn get_incident_notification_template_with_http_info(
3029        &self,
3030        id: uuid::Uuid,
3031        params: GetIncidentNotificationTemplateOptionalParams,
3032    ) -> Result<
3033        datadog::ResponseContent<crate::datadogV2::model::IncidentNotificationTemplate>,
3034        datadog::Error<GetIncidentNotificationTemplateError>,
3035    > {
3036        let local_configuration = &self.config;
3037        let operation_id = "v2.get_incident_notification_template";
3038        if local_configuration.is_unstable_operation_enabled(operation_id) {
3039            warn!("Using unstable operation {operation_id}");
3040        } else {
3041            let local_error = datadog::UnstableOperationDisabledError {
3042                msg: "Operation 'v2.get_incident_notification_template' is not enabled".to_string(),
3043            };
3044            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3045        }
3046
3047        // unbox and build optional parameters
3048        let include = params.include;
3049
3050        let local_client = &self.client;
3051
3052        let local_uri_str = format!(
3053            "{}/api/v2/incidents/config/notification-templates/{id}",
3054            local_configuration.get_operation_host(operation_id),
3055            id = datadog::urlencode(id.to_string())
3056        );
3057        let mut local_req_builder =
3058            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
3059
3060        if let Some(ref local_query_param) = include {
3061            local_req_builder =
3062                local_req_builder.query(&[("include", &local_query_param.to_string())]);
3063        };
3064
3065        // build headers
3066        let mut headers = HeaderMap::new();
3067        headers.insert("Accept", HeaderValue::from_static("application/json"));
3068
3069        // build user agent
3070        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3071            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3072            Err(e) => {
3073                log::warn!("Failed to parse user agent header: {e}, falling back to default");
3074                headers.insert(
3075                    reqwest::header::USER_AGENT,
3076                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3077                )
3078            }
3079        };
3080
3081        // build auth
3082        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3083            headers.insert(
3084                "DD-API-KEY",
3085                HeaderValue::from_str(local_key.key.as_str())
3086                    .expect("failed to parse DD-API-KEY header"),
3087            );
3088        };
3089        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3090            headers.insert(
3091                "DD-APPLICATION-KEY",
3092                HeaderValue::from_str(local_key.key.as_str())
3093                    .expect("failed to parse DD-APPLICATION-KEY header"),
3094            );
3095        };
3096
3097        local_req_builder = local_req_builder.headers(headers);
3098        let local_req = local_req_builder.build()?;
3099        log::debug!("request content: {:?}", local_req.body());
3100        let local_resp = local_client.execute(local_req).await?;
3101
3102        let local_status = local_resp.status();
3103        let local_content = local_resp.text().await?;
3104        log::debug!("response content: {}", local_content);
3105
3106        if !local_status.is_client_error() && !local_status.is_server_error() {
3107            match serde_json::from_str::<crate::datadogV2::model::IncidentNotificationTemplate>(
3108                &local_content,
3109            ) {
3110                Ok(e) => {
3111                    return Ok(datadog::ResponseContent {
3112                        status: local_status,
3113                        content: local_content,
3114                        entity: Some(e),
3115                    })
3116                }
3117                Err(e) => return Err(datadog::Error::Serde(e)),
3118            };
3119        } else {
3120            let local_entity: Option<GetIncidentNotificationTemplateError> =
3121                serde_json::from_str(&local_content).ok();
3122            let local_error = datadog::ResponseContent {
3123                status: local_status,
3124                content: local_content,
3125                entity: local_entity,
3126            };
3127            Err(datadog::Error::ResponseError(local_error))
3128        }
3129    }
3130
3131    /// Get incident todo details.
3132    pub async fn get_incident_todo(
3133        &self,
3134        incident_id: String,
3135        todo_id: String,
3136    ) -> Result<crate::datadogV2::model::IncidentTodoResponse, datadog::Error<GetIncidentTodoError>>
3137    {
3138        match self
3139            .get_incident_todo_with_http_info(incident_id, todo_id)
3140            .await
3141        {
3142            Ok(response_content) => {
3143                if let Some(e) = response_content.entity {
3144                    Ok(e)
3145                } else {
3146                    Err(datadog::Error::Serde(serde::de::Error::custom(
3147                        "response content was None",
3148                    )))
3149                }
3150            }
3151            Err(err) => Err(err),
3152        }
3153    }
3154
3155    /// Get incident todo details.
3156    pub async fn get_incident_todo_with_http_info(
3157        &self,
3158        incident_id: String,
3159        todo_id: String,
3160    ) -> Result<
3161        datadog::ResponseContent<crate::datadogV2::model::IncidentTodoResponse>,
3162        datadog::Error<GetIncidentTodoError>,
3163    > {
3164        let local_configuration = &self.config;
3165        let operation_id = "v2.get_incident_todo";
3166        if local_configuration.is_unstable_operation_enabled(operation_id) {
3167            warn!("Using unstable operation {operation_id}");
3168        } else {
3169            let local_error = datadog::UnstableOperationDisabledError {
3170                msg: "Operation 'v2.get_incident_todo' is not enabled".to_string(),
3171            };
3172            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3173        }
3174
3175        let local_client = &self.client;
3176
3177        let local_uri_str = format!(
3178            "{}/api/v2/incidents/{incident_id}/relationships/todos/{todo_id}",
3179            local_configuration.get_operation_host(operation_id),
3180            incident_id = datadog::urlencode(incident_id),
3181            todo_id = datadog::urlencode(todo_id)
3182        );
3183        let mut local_req_builder =
3184            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
3185
3186        // build headers
3187        let mut headers = HeaderMap::new();
3188        headers.insert("Accept", HeaderValue::from_static("application/json"));
3189
3190        // build user agent
3191        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3192            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3193            Err(e) => {
3194                log::warn!("Failed to parse user agent header: {e}, falling back to default");
3195                headers.insert(
3196                    reqwest::header::USER_AGENT,
3197                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3198                )
3199            }
3200        };
3201
3202        // build auth
3203        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3204            headers.insert(
3205                "DD-API-KEY",
3206                HeaderValue::from_str(local_key.key.as_str())
3207                    .expect("failed to parse DD-API-KEY header"),
3208            );
3209        };
3210        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3211            headers.insert(
3212                "DD-APPLICATION-KEY",
3213                HeaderValue::from_str(local_key.key.as_str())
3214                    .expect("failed to parse DD-APPLICATION-KEY header"),
3215            );
3216        };
3217
3218        local_req_builder = local_req_builder.headers(headers);
3219        let local_req = local_req_builder.build()?;
3220        log::debug!("request content: {:?}", local_req.body());
3221        let local_resp = local_client.execute(local_req).await?;
3222
3223        let local_status = local_resp.status();
3224        let local_content = local_resp.text().await?;
3225        log::debug!("response content: {}", local_content);
3226
3227        if !local_status.is_client_error() && !local_status.is_server_error() {
3228            match serde_json::from_str::<crate::datadogV2::model::IncidentTodoResponse>(
3229                &local_content,
3230            ) {
3231                Ok(e) => {
3232                    return Ok(datadog::ResponseContent {
3233                        status: local_status,
3234                        content: local_content,
3235                        entity: Some(e),
3236                    })
3237                }
3238                Err(e) => return Err(datadog::Error::Serde(e)),
3239            };
3240        } else {
3241            let local_entity: Option<GetIncidentTodoError> =
3242                serde_json::from_str(&local_content).ok();
3243            let local_error = datadog::ResponseContent {
3244                status: local_status,
3245                content: local_content,
3246                entity: local_entity,
3247            };
3248            Err(datadog::Error::ResponseError(local_error))
3249        }
3250    }
3251
3252    /// Get incident type details.
3253    pub async fn get_incident_type(
3254        &self,
3255        incident_type_id: String,
3256    ) -> Result<crate::datadogV2::model::IncidentTypeResponse, datadog::Error<GetIncidentTypeError>>
3257    {
3258        match self
3259            .get_incident_type_with_http_info(incident_type_id)
3260            .await
3261        {
3262            Ok(response_content) => {
3263                if let Some(e) = response_content.entity {
3264                    Ok(e)
3265                } else {
3266                    Err(datadog::Error::Serde(serde::de::Error::custom(
3267                        "response content was None",
3268                    )))
3269                }
3270            }
3271            Err(err) => Err(err),
3272        }
3273    }
3274
3275    /// Get incident type details.
3276    pub async fn get_incident_type_with_http_info(
3277        &self,
3278        incident_type_id: String,
3279    ) -> Result<
3280        datadog::ResponseContent<crate::datadogV2::model::IncidentTypeResponse>,
3281        datadog::Error<GetIncidentTypeError>,
3282    > {
3283        let local_configuration = &self.config;
3284        let operation_id = "v2.get_incident_type";
3285        if local_configuration.is_unstable_operation_enabled(operation_id) {
3286            warn!("Using unstable operation {operation_id}");
3287        } else {
3288            let local_error = datadog::UnstableOperationDisabledError {
3289                msg: "Operation 'v2.get_incident_type' is not enabled".to_string(),
3290            };
3291            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3292        }
3293
3294        let local_client = &self.client;
3295
3296        let local_uri_str = format!(
3297            "{}/api/v2/incidents/config/types/{incident_type_id}",
3298            local_configuration.get_operation_host(operation_id),
3299            incident_type_id = datadog::urlencode(incident_type_id)
3300        );
3301        let mut local_req_builder =
3302            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
3303
3304        // build headers
3305        let mut headers = HeaderMap::new();
3306        headers.insert("Accept", HeaderValue::from_static("application/json"));
3307
3308        // build user agent
3309        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3310            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3311            Err(e) => {
3312                log::warn!("Failed to parse user agent header: {e}, falling back to default");
3313                headers.insert(
3314                    reqwest::header::USER_AGENT,
3315                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3316                )
3317            }
3318        };
3319
3320        // build auth
3321        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3322            headers.insert(
3323                "DD-API-KEY",
3324                HeaderValue::from_str(local_key.key.as_str())
3325                    .expect("failed to parse DD-API-KEY header"),
3326            );
3327        };
3328        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3329            headers.insert(
3330                "DD-APPLICATION-KEY",
3331                HeaderValue::from_str(local_key.key.as_str())
3332                    .expect("failed to parse DD-APPLICATION-KEY header"),
3333            );
3334        };
3335
3336        local_req_builder = local_req_builder.headers(headers);
3337        let local_req = local_req_builder.build()?;
3338        log::debug!("request content: {:?}", local_req.body());
3339        let local_resp = local_client.execute(local_req).await?;
3340
3341        let local_status = local_resp.status();
3342        let local_content = local_resp.text().await?;
3343        log::debug!("response content: {}", local_content);
3344
3345        if !local_status.is_client_error() && !local_status.is_server_error() {
3346            match serde_json::from_str::<crate::datadogV2::model::IncidentTypeResponse>(
3347                &local_content,
3348            ) {
3349                Ok(e) => {
3350                    return Ok(datadog::ResponseContent {
3351                        status: local_status,
3352                        content: local_content,
3353                        entity: Some(e),
3354                    })
3355                }
3356                Err(e) => return Err(datadog::Error::Serde(e)),
3357            };
3358        } else {
3359            let local_entity: Option<GetIncidentTypeError> =
3360                serde_json::from_str(&local_content).ok();
3361            let local_error = datadog::ResponseContent {
3362                status: local_status,
3363                content: local_content,
3364                entity: local_entity,
3365            };
3366            Err(datadog::Error::ResponseError(local_error))
3367        }
3368    }
3369
3370    /// Get all attachments for a given incident.
3371    pub async fn list_incident_attachments(
3372        &self,
3373        incident_id: String,
3374        params: ListIncidentAttachmentsOptionalParams,
3375    ) -> Result<
3376        crate::datadogV2::model::IncidentAttachmentsResponse,
3377        datadog::Error<ListIncidentAttachmentsError>,
3378    > {
3379        match self
3380            .list_incident_attachments_with_http_info(incident_id, params)
3381            .await
3382        {
3383            Ok(response_content) => {
3384                if let Some(e) = response_content.entity {
3385                    Ok(e)
3386                } else {
3387                    Err(datadog::Error::Serde(serde::de::Error::custom(
3388                        "response content was None",
3389                    )))
3390                }
3391            }
3392            Err(err) => Err(err),
3393        }
3394    }
3395
3396    /// Get all attachments for a given incident.
3397    pub async fn list_incident_attachments_with_http_info(
3398        &self,
3399        incident_id: String,
3400        params: ListIncidentAttachmentsOptionalParams,
3401    ) -> Result<
3402        datadog::ResponseContent<crate::datadogV2::model::IncidentAttachmentsResponse>,
3403        datadog::Error<ListIncidentAttachmentsError>,
3404    > {
3405        let local_configuration = &self.config;
3406        let operation_id = "v2.list_incident_attachments";
3407        if local_configuration.is_unstable_operation_enabled(operation_id) {
3408            warn!("Using unstable operation {operation_id}");
3409        } else {
3410            let local_error = datadog::UnstableOperationDisabledError {
3411                msg: "Operation 'v2.list_incident_attachments' is not enabled".to_string(),
3412            };
3413            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3414        }
3415
3416        // unbox and build optional parameters
3417        let include = params.include;
3418        let filter_attachment_type = params.filter_attachment_type;
3419
3420        let local_client = &self.client;
3421
3422        let local_uri_str = format!(
3423            "{}/api/v2/incidents/{incident_id}/attachments",
3424            local_configuration.get_operation_host(operation_id),
3425            incident_id = datadog::urlencode(incident_id)
3426        );
3427        let mut local_req_builder =
3428            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
3429
3430        if let Some(ref local) = include {
3431            local_req_builder = local_req_builder.query(&[(
3432                "include",
3433                &local
3434                    .iter()
3435                    .map(|p| p.to_string())
3436                    .collect::<Vec<String>>()
3437                    .join(",")
3438                    .to_string(),
3439            )]);
3440        };
3441        if let Some(ref local) = filter_attachment_type {
3442            local_req_builder = local_req_builder.query(&[(
3443                "filter[attachment_type]",
3444                &local
3445                    .iter()
3446                    .map(|p| p.to_string())
3447                    .collect::<Vec<String>>()
3448                    .join(",")
3449                    .to_string(),
3450            )]);
3451        };
3452
3453        // build headers
3454        let mut headers = HeaderMap::new();
3455        headers.insert("Accept", HeaderValue::from_static("application/json"));
3456
3457        // build user agent
3458        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3459            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3460            Err(e) => {
3461                log::warn!("Failed to parse user agent header: {e}, falling back to default");
3462                headers.insert(
3463                    reqwest::header::USER_AGENT,
3464                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3465                )
3466            }
3467        };
3468
3469        // build auth
3470        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3471            headers.insert(
3472                "DD-API-KEY",
3473                HeaderValue::from_str(local_key.key.as_str())
3474                    .expect("failed to parse DD-API-KEY header"),
3475            );
3476        };
3477        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3478            headers.insert(
3479                "DD-APPLICATION-KEY",
3480                HeaderValue::from_str(local_key.key.as_str())
3481                    .expect("failed to parse DD-APPLICATION-KEY header"),
3482            );
3483        };
3484
3485        local_req_builder = local_req_builder.headers(headers);
3486        let local_req = local_req_builder.build()?;
3487        log::debug!("request content: {:?}", local_req.body());
3488        let local_resp = local_client.execute(local_req).await?;
3489
3490        let local_status = local_resp.status();
3491        let local_content = local_resp.text().await?;
3492        log::debug!("response content: {}", local_content);
3493
3494        if !local_status.is_client_error() && !local_status.is_server_error() {
3495            match serde_json::from_str::<crate::datadogV2::model::IncidentAttachmentsResponse>(
3496                &local_content,
3497            ) {
3498                Ok(e) => {
3499                    return Ok(datadog::ResponseContent {
3500                        status: local_status,
3501                        content: local_content,
3502                        entity: Some(e),
3503                    })
3504                }
3505                Err(e) => return Err(datadog::Error::Serde(e)),
3506            };
3507        } else {
3508            let local_entity: Option<ListIncidentAttachmentsError> =
3509                serde_json::from_str(&local_content).ok();
3510            let local_error = datadog::ResponseContent {
3511                status: local_status,
3512                content: local_content,
3513                entity: local_entity,
3514            };
3515            Err(datadog::Error::ResponseError(local_error))
3516        }
3517    }
3518
3519    /// Get all impacts for an incident.
3520    pub async fn list_incident_impacts(
3521        &self,
3522        incident_id: String,
3523        params: ListIncidentImpactsOptionalParams,
3524    ) -> Result<
3525        crate::datadogV2::model::IncidentImpactsResponse,
3526        datadog::Error<ListIncidentImpactsError>,
3527    > {
3528        match self
3529            .list_incident_impacts_with_http_info(incident_id, params)
3530            .await
3531        {
3532            Ok(response_content) => {
3533                if let Some(e) = response_content.entity {
3534                    Ok(e)
3535                } else {
3536                    Err(datadog::Error::Serde(serde::de::Error::custom(
3537                        "response content was None",
3538                    )))
3539                }
3540            }
3541            Err(err) => Err(err),
3542        }
3543    }
3544
3545    /// Get all impacts for an incident.
3546    pub async fn list_incident_impacts_with_http_info(
3547        &self,
3548        incident_id: String,
3549        params: ListIncidentImpactsOptionalParams,
3550    ) -> Result<
3551        datadog::ResponseContent<crate::datadogV2::model::IncidentImpactsResponse>,
3552        datadog::Error<ListIncidentImpactsError>,
3553    > {
3554        let local_configuration = &self.config;
3555        let operation_id = "v2.list_incident_impacts";
3556        if local_configuration.is_unstable_operation_enabled(operation_id) {
3557            warn!("Using unstable operation {operation_id}");
3558        } else {
3559            let local_error = datadog::UnstableOperationDisabledError {
3560                msg: "Operation 'v2.list_incident_impacts' is not enabled".to_string(),
3561            };
3562            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3563        }
3564
3565        // unbox and build optional parameters
3566        let include = params.include;
3567
3568        let local_client = &self.client;
3569
3570        let local_uri_str = format!(
3571            "{}/api/v2/incidents/{incident_id}/impacts",
3572            local_configuration.get_operation_host(operation_id),
3573            incident_id = datadog::urlencode(incident_id)
3574        );
3575        let mut local_req_builder =
3576            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
3577
3578        if let Some(ref local) = include {
3579            local_req_builder = local_req_builder.query(&[(
3580                "include",
3581                &local
3582                    .iter()
3583                    .map(|p| p.to_string())
3584                    .collect::<Vec<String>>()
3585                    .join(",")
3586                    .to_string(),
3587            )]);
3588        };
3589
3590        // build headers
3591        let mut headers = HeaderMap::new();
3592        headers.insert("Accept", HeaderValue::from_static("application/json"));
3593
3594        // build user agent
3595        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3596            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3597            Err(e) => {
3598                log::warn!("Failed to parse user agent header: {e}, falling back to default");
3599                headers.insert(
3600                    reqwest::header::USER_AGENT,
3601                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3602                )
3603            }
3604        };
3605
3606        // build auth
3607        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3608            headers.insert(
3609                "DD-API-KEY",
3610                HeaderValue::from_str(local_key.key.as_str())
3611                    .expect("failed to parse DD-API-KEY header"),
3612            );
3613        };
3614        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3615            headers.insert(
3616                "DD-APPLICATION-KEY",
3617                HeaderValue::from_str(local_key.key.as_str())
3618                    .expect("failed to parse DD-APPLICATION-KEY header"),
3619            );
3620        };
3621
3622        local_req_builder = local_req_builder.headers(headers);
3623        let local_req = local_req_builder.build()?;
3624        log::debug!("request content: {:?}", local_req.body());
3625        let local_resp = local_client.execute(local_req).await?;
3626
3627        let local_status = local_resp.status();
3628        let local_content = local_resp.text().await?;
3629        log::debug!("response content: {}", local_content);
3630
3631        if !local_status.is_client_error() && !local_status.is_server_error() {
3632            match serde_json::from_str::<crate::datadogV2::model::IncidentImpactsResponse>(
3633                &local_content,
3634            ) {
3635                Ok(e) => {
3636                    return Ok(datadog::ResponseContent {
3637                        status: local_status,
3638                        content: local_content,
3639                        entity: Some(e),
3640                    })
3641                }
3642                Err(e) => return Err(datadog::Error::Serde(e)),
3643            };
3644        } else {
3645            let local_entity: Option<ListIncidentImpactsError> =
3646                serde_json::from_str(&local_content).ok();
3647            let local_error = datadog::ResponseContent {
3648                status: local_status,
3649                content: local_content,
3650                entity: local_entity,
3651            };
3652            Err(datadog::Error::ResponseError(local_error))
3653        }
3654    }
3655
3656    /// Get all integration metadata for an incident.
3657    pub async fn list_incident_integrations(
3658        &self,
3659        incident_id: String,
3660    ) -> Result<
3661        crate::datadogV2::model::IncidentIntegrationMetadataListResponse,
3662        datadog::Error<ListIncidentIntegrationsError>,
3663    > {
3664        match self
3665            .list_incident_integrations_with_http_info(incident_id)
3666            .await
3667        {
3668            Ok(response_content) => {
3669                if let Some(e) = response_content.entity {
3670                    Ok(e)
3671                } else {
3672                    Err(datadog::Error::Serde(serde::de::Error::custom(
3673                        "response content was None",
3674                    )))
3675                }
3676            }
3677            Err(err) => Err(err),
3678        }
3679    }
3680
3681    /// Get all integration metadata for an incident.
3682    pub async fn list_incident_integrations_with_http_info(
3683        &self,
3684        incident_id: String,
3685    ) -> Result<
3686        datadog::ResponseContent<crate::datadogV2::model::IncidentIntegrationMetadataListResponse>,
3687        datadog::Error<ListIncidentIntegrationsError>,
3688    > {
3689        let local_configuration = &self.config;
3690        let operation_id = "v2.list_incident_integrations";
3691        if local_configuration.is_unstable_operation_enabled(operation_id) {
3692            warn!("Using unstable operation {operation_id}");
3693        } else {
3694            let local_error = datadog::UnstableOperationDisabledError {
3695                msg: "Operation 'v2.list_incident_integrations' is not enabled".to_string(),
3696            };
3697            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3698        }
3699
3700        let local_client = &self.client;
3701
3702        let local_uri_str = format!(
3703            "{}/api/v2/incidents/{incident_id}/relationships/integrations",
3704            local_configuration.get_operation_host(operation_id),
3705            incident_id = datadog::urlencode(incident_id)
3706        );
3707        let mut local_req_builder =
3708            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
3709
3710        // build headers
3711        let mut headers = HeaderMap::new();
3712        headers.insert("Accept", HeaderValue::from_static("application/json"));
3713
3714        // build user agent
3715        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3716            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3717            Err(e) => {
3718                log::warn!("Failed to parse user agent header: {e}, falling back to default");
3719                headers.insert(
3720                    reqwest::header::USER_AGENT,
3721                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3722                )
3723            }
3724        };
3725
3726        // build auth
3727        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3728            headers.insert(
3729                "DD-API-KEY",
3730                HeaderValue::from_str(local_key.key.as_str())
3731                    .expect("failed to parse DD-API-KEY header"),
3732            );
3733        };
3734        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3735            headers.insert(
3736                "DD-APPLICATION-KEY",
3737                HeaderValue::from_str(local_key.key.as_str())
3738                    .expect("failed to parse DD-APPLICATION-KEY header"),
3739            );
3740        };
3741
3742        local_req_builder = local_req_builder.headers(headers);
3743        let local_req = local_req_builder.build()?;
3744        log::debug!("request content: {:?}", local_req.body());
3745        let local_resp = local_client.execute(local_req).await?;
3746
3747        let local_status = local_resp.status();
3748        let local_content = local_resp.text().await?;
3749        log::debug!("response content: {}", local_content);
3750
3751        if !local_status.is_client_error() && !local_status.is_server_error() {
3752            match serde_json::from_str::<
3753                crate::datadogV2::model::IncidentIntegrationMetadataListResponse,
3754            >(&local_content)
3755            {
3756                Ok(e) => {
3757                    return Ok(datadog::ResponseContent {
3758                        status: local_status,
3759                        content: local_content,
3760                        entity: Some(e),
3761                    })
3762                }
3763                Err(e) => return Err(datadog::Error::Serde(e)),
3764            };
3765        } else {
3766            let local_entity: Option<ListIncidentIntegrationsError> =
3767                serde_json::from_str(&local_content).ok();
3768            let local_error = datadog::ResponseContent {
3769                status: local_status,
3770                content: local_content,
3771                entity: local_entity,
3772            };
3773            Err(datadog::Error::ResponseError(local_error))
3774        }
3775    }
3776
3777    /// Lists all notification rules for the organization. Optionally filter by incident type.
3778    pub async fn list_incident_notification_rules(
3779        &self,
3780        params: ListIncidentNotificationRulesOptionalParams,
3781    ) -> Result<
3782        crate::datadogV2::model::IncidentNotificationRuleArray,
3783        datadog::Error<ListIncidentNotificationRulesError>,
3784    > {
3785        match self
3786            .list_incident_notification_rules_with_http_info(params)
3787            .await
3788        {
3789            Ok(response_content) => {
3790                if let Some(e) = response_content.entity {
3791                    Ok(e)
3792                } else {
3793                    Err(datadog::Error::Serde(serde::de::Error::custom(
3794                        "response content was None",
3795                    )))
3796                }
3797            }
3798            Err(err) => Err(err),
3799        }
3800    }
3801
3802    /// Lists all notification rules for the organization. Optionally filter by incident type.
3803    pub async fn list_incident_notification_rules_with_http_info(
3804        &self,
3805        params: ListIncidentNotificationRulesOptionalParams,
3806    ) -> Result<
3807        datadog::ResponseContent<crate::datadogV2::model::IncidentNotificationRuleArray>,
3808        datadog::Error<ListIncidentNotificationRulesError>,
3809    > {
3810        let local_configuration = &self.config;
3811        let operation_id = "v2.list_incident_notification_rules";
3812        if local_configuration.is_unstable_operation_enabled(operation_id) {
3813            warn!("Using unstable operation {operation_id}");
3814        } else {
3815            let local_error = datadog::UnstableOperationDisabledError {
3816                msg: "Operation 'v2.list_incident_notification_rules' is not enabled".to_string(),
3817            };
3818            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3819        }
3820
3821        // unbox and build optional parameters
3822        let include = params.include;
3823
3824        let local_client = &self.client;
3825
3826        let local_uri_str = format!(
3827            "{}/api/v2/incidents/config/notification-rules",
3828            local_configuration.get_operation_host(operation_id)
3829        );
3830        let mut local_req_builder =
3831            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
3832
3833        if let Some(ref local_query_param) = include {
3834            local_req_builder =
3835                local_req_builder.query(&[("include", &local_query_param.to_string())]);
3836        };
3837
3838        // build headers
3839        let mut headers = HeaderMap::new();
3840        headers.insert("Accept", HeaderValue::from_static("application/json"));
3841
3842        // build user agent
3843        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3844            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3845            Err(e) => {
3846                log::warn!("Failed to parse user agent header: {e}, falling back to default");
3847                headers.insert(
3848                    reqwest::header::USER_AGENT,
3849                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3850                )
3851            }
3852        };
3853
3854        // build auth
3855        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3856            headers.insert(
3857                "DD-API-KEY",
3858                HeaderValue::from_str(local_key.key.as_str())
3859                    .expect("failed to parse DD-API-KEY header"),
3860            );
3861        };
3862        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3863            headers.insert(
3864                "DD-APPLICATION-KEY",
3865                HeaderValue::from_str(local_key.key.as_str())
3866                    .expect("failed to parse DD-APPLICATION-KEY header"),
3867            );
3868        };
3869
3870        local_req_builder = local_req_builder.headers(headers);
3871        let local_req = local_req_builder.build()?;
3872        log::debug!("request content: {:?}", local_req.body());
3873        let local_resp = local_client.execute(local_req).await?;
3874
3875        let local_status = local_resp.status();
3876        let local_content = local_resp.text().await?;
3877        log::debug!("response content: {}", local_content);
3878
3879        if !local_status.is_client_error() && !local_status.is_server_error() {
3880            match serde_json::from_str::<crate::datadogV2::model::IncidentNotificationRuleArray>(
3881                &local_content,
3882            ) {
3883                Ok(e) => {
3884                    return Ok(datadog::ResponseContent {
3885                        status: local_status,
3886                        content: local_content,
3887                        entity: Some(e),
3888                    })
3889                }
3890                Err(e) => return Err(datadog::Error::Serde(e)),
3891            };
3892        } else {
3893            let local_entity: Option<ListIncidentNotificationRulesError> =
3894                serde_json::from_str(&local_content).ok();
3895            let local_error = datadog::ResponseContent {
3896                status: local_status,
3897                content: local_content,
3898                entity: local_entity,
3899            };
3900            Err(datadog::Error::ResponseError(local_error))
3901        }
3902    }
3903
3904    /// Lists all notification templates. Optionally filter by incident type.
3905    pub async fn list_incident_notification_templates(
3906        &self,
3907        params: ListIncidentNotificationTemplatesOptionalParams,
3908    ) -> Result<
3909        crate::datadogV2::model::IncidentNotificationTemplateArray,
3910        datadog::Error<ListIncidentNotificationTemplatesError>,
3911    > {
3912        match self
3913            .list_incident_notification_templates_with_http_info(params)
3914            .await
3915        {
3916            Ok(response_content) => {
3917                if let Some(e) = response_content.entity {
3918                    Ok(e)
3919                } else {
3920                    Err(datadog::Error::Serde(serde::de::Error::custom(
3921                        "response content was None",
3922                    )))
3923                }
3924            }
3925            Err(err) => Err(err),
3926        }
3927    }
3928
3929    /// Lists all notification templates. Optionally filter by incident type.
3930    pub async fn list_incident_notification_templates_with_http_info(
3931        &self,
3932        params: ListIncidentNotificationTemplatesOptionalParams,
3933    ) -> Result<
3934        datadog::ResponseContent<crate::datadogV2::model::IncidentNotificationTemplateArray>,
3935        datadog::Error<ListIncidentNotificationTemplatesError>,
3936    > {
3937        let local_configuration = &self.config;
3938        let operation_id = "v2.list_incident_notification_templates";
3939        if local_configuration.is_unstable_operation_enabled(operation_id) {
3940            warn!("Using unstable operation {operation_id}");
3941        } else {
3942            let local_error = datadog::UnstableOperationDisabledError {
3943                msg: "Operation 'v2.list_incident_notification_templates' is not enabled"
3944                    .to_string(),
3945            };
3946            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3947        }
3948
3949        // unbox and build optional parameters
3950        let filter_incident_type = params.filter_incident_type;
3951        let include = params.include;
3952
3953        let local_client = &self.client;
3954
3955        let local_uri_str = format!(
3956            "{}/api/v2/incidents/config/notification-templates",
3957            local_configuration.get_operation_host(operation_id)
3958        );
3959        let mut local_req_builder =
3960            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
3961
3962        if let Some(ref local_query_param) = filter_incident_type {
3963            local_req_builder = local_req_builder
3964                .query(&[("filter[incident-type]", &local_query_param.to_string())]);
3965        };
3966        if let Some(ref local_query_param) = include {
3967            local_req_builder =
3968                local_req_builder.query(&[("include", &local_query_param.to_string())]);
3969        };
3970
3971        // build headers
3972        let mut headers = HeaderMap::new();
3973        headers.insert("Accept", HeaderValue::from_static("application/json"));
3974
3975        // build user agent
3976        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3977            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3978            Err(e) => {
3979                log::warn!("Failed to parse user agent header: {e}, falling back to default");
3980                headers.insert(
3981                    reqwest::header::USER_AGENT,
3982                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3983                )
3984            }
3985        };
3986
3987        // build auth
3988        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3989            headers.insert(
3990                "DD-API-KEY",
3991                HeaderValue::from_str(local_key.key.as_str())
3992                    .expect("failed to parse DD-API-KEY header"),
3993            );
3994        };
3995        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3996            headers.insert(
3997                "DD-APPLICATION-KEY",
3998                HeaderValue::from_str(local_key.key.as_str())
3999                    .expect("failed to parse DD-APPLICATION-KEY header"),
4000            );
4001        };
4002
4003        local_req_builder = local_req_builder.headers(headers);
4004        let local_req = local_req_builder.build()?;
4005        log::debug!("request content: {:?}", local_req.body());
4006        let local_resp = local_client.execute(local_req).await?;
4007
4008        let local_status = local_resp.status();
4009        let local_content = local_resp.text().await?;
4010        log::debug!("response content: {}", local_content);
4011
4012        if !local_status.is_client_error() && !local_status.is_server_error() {
4013            match serde_json::from_str::<crate::datadogV2::model::IncidentNotificationTemplateArray>(
4014                &local_content,
4015            ) {
4016                Ok(e) => {
4017                    return Ok(datadog::ResponseContent {
4018                        status: local_status,
4019                        content: local_content,
4020                        entity: Some(e),
4021                    })
4022                }
4023                Err(e) => return Err(datadog::Error::Serde(e)),
4024            };
4025        } else {
4026            let local_entity: Option<ListIncidentNotificationTemplatesError> =
4027                serde_json::from_str(&local_content).ok();
4028            let local_error = datadog::ResponseContent {
4029                status: local_status,
4030                content: local_content,
4031                entity: local_entity,
4032            };
4033            Err(datadog::Error::ResponseError(local_error))
4034        }
4035    }
4036
4037    /// Get all todos for an incident.
4038    pub async fn list_incident_todos(
4039        &self,
4040        incident_id: String,
4041    ) -> Result<
4042        crate::datadogV2::model::IncidentTodoListResponse,
4043        datadog::Error<ListIncidentTodosError>,
4044    > {
4045        match self.list_incident_todos_with_http_info(incident_id).await {
4046            Ok(response_content) => {
4047                if let Some(e) = response_content.entity {
4048                    Ok(e)
4049                } else {
4050                    Err(datadog::Error::Serde(serde::de::Error::custom(
4051                        "response content was None",
4052                    )))
4053                }
4054            }
4055            Err(err) => Err(err),
4056        }
4057    }
4058
4059    /// Get all todos for an incident.
4060    pub async fn list_incident_todos_with_http_info(
4061        &self,
4062        incident_id: String,
4063    ) -> Result<
4064        datadog::ResponseContent<crate::datadogV2::model::IncidentTodoListResponse>,
4065        datadog::Error<ListIncidentTodosError>,
4066    > {
4067        let local_configuration = &self.config;
4068        let operation_id = "v2.list_incident_todos";
4069        if local_configuration.is_unstable_operation_enabled(operation_id) {
4070            warn!("Using unstable operation {operation_id}");
4071        } else {
4072            let local_error = datadog::UnstableOperationDisabledError {
4073                msg: "Operation 'v2.list_incident_todos' is not enabled".to_string(),
4074            };
4075            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
4076        }
4077
4078        let local_client = &self.client;
4079
4080        let local_uri_str = format!(
4081            "{}/api/v2/incidents/{incident_id}/relationships/todos",
4082            local_configuration.get_operation_host(operation_id),
4083            incident_id = datadog::urlencode(incident_id)
4084        );
4085        let mut local_req_builder =
4086            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
4087
4088        // build headers
4089        let mut headers = HeaderMap::new();
4090        headers.insert("Accept", HeaderValue::from_static("application/json"));
4091
4092        // build user agent
4093        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
4094            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
4095            Err(e) => {
4096                log::warn!("Failed to parse user agent header: {e}, falling back to default");
4097                headers.insert(
4098                    reqwest::header::USER_AGENT,
4099                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
4100                )
4101            }
4102        };
4103
4104        // build auth
4105        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
4106            headers.insert(
4107                "DD-API-KEY",
4108                HeaderValue::from_str(local_key.key.as_str())
4109                    .expect("failed to parse DD-API-KEY header"),
4110            );
4111        };
4112        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
4113            headers.insert(
4114                "DD-APPLICATION-KEY",
4115                HeaderValue::from_str(local_key.key.as_str())
4116                    .expect("failed to parse DD-APPLICATION-KEY header"),
4117            );
4118        };
4119
4120        local_req_builder = local_req_builder.headers(headers);
4121        let local_req = local_req_builder.build()?;
4122        log::debug!("request content: {:?}", local_req.body());
4123        let local_resp = local_client.execute(local_req).await?;
4124
4125        let local_status = local_resp.status();
4126        let local_content = local_resp.text().await?;
4127        log::debug!("response content: {}", local_content);
4128
4129        if !local_status.is_client_error() && !local_status.is_server_error() {
4130            match serde_json::from_str::<crate::datadogV2::model::IncidentTodoListResponse>(
4131                &local_content,
4132            ) {
4133                Ok(e) => {
4134                    return Ok(datadog::ResponseContent {
4135                        status: local_status,
4136                        content: local_content,
4137                        entity: Some(e),
4138                    })
4139                }
4140                Err(e) => return Err(datadog::Error::Serde(e)),
4141            };
4142        } else {
4143            let local_entity: Option<ListIncidentTodosError> =
4144                serde_json::from_str(&local_content).ok();
4145            let local_error = datadog::ResponseContent {
4146                status: local_status,
4147                content: local_content,
4148                entity: local_entity,
4149            };
4150            Err(datadog::Error::ResponseError(local_error))
4151        }
4152    }
4153
4154    /// Get all incident types.
4155    pub async fn list_incident_types(
4156        &self,
4157        params: ListIncidentTypesOptionalParams,
4158    ) -> Result<
4159        crate::datadogV2::model::IncidentTypeListResponse,
4160        datadog::Error<ListIncidentTypesError>,
4161    > {
4162        match self.list_incident_types_with_http_info(params).await {
4163            Ok(response_content) => {
4164                if let Some(e) = response_content.entity {
4165                    Ok(e)
4166                } else {
4167                    Err(datadog::Error::Serde(serde::de::Error::custom(
4168                        "response content was None",
4169                    )))
4170                }
4171            }
4172            Err(err) => Err(err),
4173        }
4174    }
4175
4176    /// Get all incident types.
4177    pub async fn list_incident_types_with_http_info(
4178        &self,
4179        params: ListIncidentTypesOptionalParams,
4180    ) -> Result<
4181        datadog::ResponseContent<crate::datadogV2::model::IncidentTypeListResponse>,
4182        datadog::Error<ListIncidentTypesError>,
4183    > {
4184        let local_configuration = &self.config;
4185        let operation_id = "v2.list_incident_types";
4186        if local_configuration.is_unstable_operation_enabled(operation_id) {
4187            warn!("Using unstable operation {operation_id}");
4188        } else {
4189            let local_error = datadog::UnstableOperationDisabledError {
4190                msg: "Operation 'v2.list_incident_types' is not enabled".to_string(),
4191            };
4192            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
4193        }
4194
4195        // unbox and build optional parameters
4196        let include_deleted = params.include_deleted;
4197
4198        let local_client = &self.client;
4199
4200        let local_uri_str = format!(
4201            "{}/api/v2/incidents/config/types",
4202            local_configuration.get_operation_host(operation_id)
4203        );
4204        let mut local_req_builder =
4205            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
4206
4207        if let Some(ref local_query_param) = include_deleted {
4208            local_req_builder =
4209                local_req_builder.query(&[("include_deleted", &local_query_param.to_string())]);
4210        };
4211
4212        // build headers
4213        let mut headers = HeaderMap::new();
4214        headers.insert("Accept", HeaderValue::from_static("application/json"));
4215
4216        // build user agent
4217        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
4218            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
4219            Err(e) => {
4220                log::warn!("Failed to parse user agent header: {e}, falling back to default");
4221                headers.insert(
4222                    reqwest::header::USER_AGENT,
4223                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
4224                )
4225            }
4226        };
4227
4228        // build auth
4229        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
4230            headers.insert(
4231                "DD-API-KEY",
4232                HeaderValue::from_str(local_key.key.as_str())
4233                    .expect("failed to parse DD-API-KEY header"),
4234            );
4235        };
4236        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
4237            headers.insert(
4238                "DD-APPLICATION-KEY",
4239                HeaderValue::from_str(local_key.key.as_str())
4240                    .expect("failed to parse DD-APPLICATION-KEY header"),
4241            );
4242        };
4243
4244        local_req_builder = local_req_builder.headers(headers);
4245        let local_req = local_req_builder.build()?;
4246        log::debug!("request content: {:?}", local_req.body());
4247        let local_resp = local_client.execute(local_req).await?;
4248
4249        let local_status = local_resp.status();
4250        let local_content = local_resp.text().await?;
4251        log::debug!("response content: {}", local_content);
4252
4253        if !local_status.is_client_error() && !local_status.is_server_error() {
4254            match serde_json::from_str::<crate::datadogV2::model::IncidentTypeListResponse>(
4255                &local_content,
4256            ) {
4257                Ok(e) => {
4258                    return Ok(datadog::ResponseContent {
4259                        status: local_status,
4260                        content: local_content,
4261                        entity: Some(e),
4262                    })
4263                }
4264                Err(e) => return Err(datadog::Error::Serde(e)),
4265            };
4266        } else {
4267            let local_entity: Option<ListIncidentTypesError> =
4268                serde_json::from_str(&local_content).ok();
4269            let local_error = datadog::ResponseContent {
4270                status: local_status,
4271                content: local_content,
4272                entity: local_entity,
4273            };
4274            Err(datadog::Error::ResponseError(local_error))
4275        }
4276    }
4277
4278    /// Get all incidents for the user's organization.
4279    pub async fn list_incidents(
4280        &self,
4281        params: ListIncidentsOptionalParams,
4282    ) -> Result<crate::datadogV2::model::IncidentsResponse, datadog::Error<ListIncidentsError>>
4283    {
4284        match self.list_incidents_with_http_info(params).await {
4285            Ok(response_content) => {
4286                if let Some(e) = response_content.entity {
4287                    Ok(e)
4288                } else {
4289                    Err(datadog::Error::Serde(serde::de::Error::custom(
4290                        "response content was None",
4291                    )))
4292                }
4293            }
4294            Err(err) => Err(err),
4295        }
4296    }
4297
4298    pub fn list_incidents_with_pagination(
4299        &self,
4300        mut params: ListIncidentsOptionalParams,
4301    ) -> impl Stream<
4302        Item = Result<
4303            crate::datadogV2::model::IncidentResponseData,
4304            datadog::Error<ListIncidentsError>,
4305        >,
4306    > + '_ {
4307        try_stream! {
4308            let mut page_size: i64 = 10;
4309            if params.page_size.is_none() {
4310                params.page_size = Some(page_size);
4311            } else {
4312                page_size = params.page_size.unwrap().clone();
4313            }
4314            loop {
4315                let resp = self.list_incidents(params.clone()).await?;
4316
4317                let r = resp.data;
4318                let count = r.len();
4319                for team in r {
4320                    yield team;
4321                }
4322
4323                if count < page_size as usize {
4324                    break;
4325                }
4326                if params.page_offset.is_none() {
4327                    params.page_offset = Some(page_size.clone());
4328                } else {
4329                    params.page_offset = Some(params.page_offset.unwrap() + page_size.clone());
4330                }
4331            }
4332        }
4333    }
4334
4335    /// Get all incidents for the user's organization.
4336    pub async fn list_incidents_with_http_info(
4337        &self,
4338        params: ListIncidentsOptionalParams,
4339    ) -> Result<
4340        datadog::ResponseContent<crate::datadogV2::model::IncidentsResponse>,
4341        datadog::Error<ListIncidentsError>,
4342    > {
4343        let local_configuration = &self.config;
4344        let operation_id = "v2.list_incidents";
4345        if local_configuration.is_unstable_operation_enabled(operation_id) {
4346            warn!("Using unstable operation {operation_id}");
4347        } else {
4348            let local_error = datadog::UnstableOperationDisabledError {
4349                msg: "Operation 'v2.list_incidents' is not enabled".to_string(),
4350            };
4351            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
4352        }
4353
4354        // unbox and build optional parameters
4355        let include = params.include;
4356        let page_size = params.page_size;
4357        let page_offset = params.page_offset;
4358
4359        let local_client = &self.client;
4360
4361        let local_uri_str = format!(
4362            "{}/api/v2/incidents",
4363            local_configuration.get_operation_host(operation_id)
4364        );
4365        let mut local_req_builder =
4366            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
4367
4368        if let Some(ref local) = include {
4369            local_req_builder = local_req_builder.query(&[(
4370                "include",
4371                &local
4372                    .iter()
4373                    .map(|p| p.to_string())
4374                    .collect::<Vec<String>>()
4375                    .join(",")
4376                    .to_string(),
4377            )]);
4378        };
4379        if let Some(ref local_query_param) = page_size {
4380            local_req_builder =
4381                local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
4382        };
4383        if let Some(ref local_query_param) = page_offset {
4384            local_req_builder =
4385                local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
4386        };
4387
4388        // build headers
4389        let mut headers = HeaderMap::new();
4390        headers.insert("Accept", HeaderValue::from_static("application/json"));
4391
4392        // build user agent
4393        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
4394            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
4395            Err(e) => {
4396                log::warn!("Failed to parse user agent header: {e}, falling back to default");
4397                headers.insert(
4398                    reqwest::header::USER_AGENT,
4399                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
4400                )
4401            }
4402        };
4403
4404        // build auth
4405        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
4406            headers.insert(
4407                "DD-API-KEY",
4408                HeaderValue::from_str(local_key.key.as_str())
4409                    .expect("failed to parse DD-API-KEY header"),
4410            );
4411        };
4412        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
4413            headers.insert(
4414                "DD-APPLICATION-KEY",
4415                HeaderValue::from_str(local_key.key.as_str())
4416                    .expect("failed to parse DD-APPLICATION-KEY header"),
4417            );
4418        };
4419
4420        local_req_builder = local_req_builder.headers(headers);
4421        let local_req = local_req_builder.build()?;
4422        log::debug!("request content: {:?}", local_req.body());
4423        let local_resp = local_client.execute(local_req).await?;
4424
4425        let local_status = local_resp.status();
4426        let local_content = local_resp.text().await?;
4427        log::debug!("response content: {}", local_content);
4428
4429        if !local_status.is_client_error() && !local_status.is_server_error() {
4430            match serde_json::from_str::<crate::datadogV2::model::IncidentsResponse>(&local_content)
4431            {
4432                Ok(e) => {
4433                    return Ok(datadog::ResponseContent {
4434                        status: local_status,
4435                        content: local_content,
4436                        entity: Some(e),
4437                    })
4438                }
4439                Err(e) => return Err(datadog::Error::Serde(e)),
4440            };
4441        } else {
4442            let local_entity: Option<ListIncidentsError> =
4443                serde_json::from_str(&local_content).ok();
4444            let local_error = datadog::ResponseContent {
4445                status: local_status,
4446                content: local_content,
4447                entity: local_entity,
4448            };
4449            Err(datadog::Error::ResponseError(local_error))
4450        }
4451    }
4452
4453    /// Search for incidents matching a certain query.
4454    pub async fn search_incidents(
4455        &self,
4456        query: String,
4457        params: SearchIncidentsOptionalParams,
4458    ) -> Result<crate::datadogV2::model::IncidentSearchResponse, datadog::Error<SearchIncidentsError>>
4459    {
4460        match self.search_incidents_with_http_info(query, params).await {
4461            Ok(response_content) => {
4462                if let Some(e) = response_content.entity {
4463                    Ok(e)
4464                } else {
4465                    Err(datadog::Error::Serde(serde::de::Error::custom(
4466                        "response content was None",
4467                    )))
4468                }
4469            }
4470            Err(err) => Err(err),
4471        }
4472    }
4473
4474    pub fn search_incidents_with_pagination(
4475        &self,
4476        query: String,
4477        mut params: SearchIncidentsOptionalParams,
4478    ) -> impl Stream<
4479        Item = Result<
4480            crate::datadogV2::model::IncidentSearchResponseIncidentsData,
4481            datadog::Error<SearchIncidentsError>,
4482        >,
4483    > + '_ {
4484        try_stream! {
4485            let mut page_size: i64 = 10;
4486            if params.page_size.is_none() {
4487                params.page_size = Some(page_size);
4488            } else {
4489                page_size = params.page_size.unwrap().clone();
4490            }
4491            loop {
4492                let resp = self.search_incidents( query.clone(),params.clone()).await?;
4493                let Some(attributes) = resp.data.attributes else { break };
4494
4495                let r = attributes.incidents;
4496                let count = r.len();
4497                for team in r {
4498                    yield team;
4499                }
4500
4501                if count < page_size as usize {
4502                    break;
4503                }
4504                if params.page_offset.is_none() {
4505                    params.page_offset = Some(page_size.clone());
4506                } else {
4507                    params.page_offset = Some(params.page_offset.unwrap() + page_size.clone());
4508                }
4509            }
4510        }
4511    }
4512
4513    /// Search for incidents matching a certain query.
4514    pub async fn search_incidents_with_http_info(
4515        &self,
4516        query: String,
4517        params: SearchIncidentsOptionalParams,
4518    ) -> Result<
4519        datadog::ResponseContent<crate::datadogV2::model::IncidentSearchResponse>,
4520        datadog::Error<SearchIncidentsError>,
4521    > {
4522        let local_configuration = &self.config;
4523        let operation_id = "v2.search_incidents";
4524        if local_configuration.is_unstable_operation_enabled(operation_id) {
4525            warn!("Using unstable operation {operation_id}");
4526        } else {
4527            let local_error = datadog::UnstableOperationDisabledError {
4528                msg: "Operation 'v2.search_incidents' is not enabled".to_string(),
4529            };
4530            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
4531        }
4532
4533        // unbox and build optional parameters
4534        let include = params.include;
4535        let sort = params.sort;
4536        let page_size = params.page_size;
4537        let page_offset = params.page_offset;
4538
4539        let local_client = &self.client;
4540
4541        let local_uri_str = format!(
4542            "{}/api/v2/incidents/search",
4543            local_configuration.get_operation_host(operation_id)
4544        );
4545        let mut local_req_builder =
4546            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
4547
4548        local_req_builder = local_req_builder.query(&[("query", &query.to_string())]);
4549        if let Some(ref local_query_param) = include {
4550            local_req_builder =
4551                local_req_builder.query(&[("include", &local_query_param.to_string())]);
4552        };
4553        if let Some(ref local_query_param) = sort {
4554            local_req_builder =
4555                local_req_builder.query(&[("sort", &local_query_param.to_string())]);
4556        };
4557        if let Some(ref local_query_param) = page_size {
4558            local_req_builder =
4559                local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
4560        };
4561        if let Some(ref local_query_param) = page_offset {
4562            local_req_builder =
4563                local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
4564        };
4565
4566        // build headers
4567        let mut headers = HeaderMap::new();
4568        headers.insert("Accept", HeaderValue::from_static("application/json"));
4569
4570        // build user agent
4571        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
4572            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
4573            Err(e) => {
4574                log::warn!("Failed to parse user agent header: {e}, falling back to default");
4575                headers.insert(
4576                    reqwest::header::USER_AGENT,
4577                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
4578                )
4579            }
4580        };
4581
4582        // build auth
4583        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
4584            headers.insert(
4585                "DD-API-KEY",
4586                HeaderValue::from_str(local_key.key.as_str())
4587                    .expect("failed to parse DD-API-KEY header"),
4588            );
4589        };
4590        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
4591            headers.insert(
4592                "DD-APPLICATION-KEY",
4593                HeaderValue::from_str(local_key.key.as_str())
4594                    .expect("failed to parse DD-APPLICATION-KEY header"),
4595            );
4596        };
4597
4598        local_req_builder = local_req_builder.headers(headers);
4599        let local_req = local_req_builder.build()?;
4600        log::debug!("request content: {:?}", local_req.body());
4601        let local_resp = local_client.execute(local_req).await?;
4602
4603        let local_status = local_resp.status();
4604        let local_content = local_resp.text().await?;
4605        log::debug!("response content: {}", local_content);
4606
4607        if !local_status.is_client_error() && !local_status.is_server_error() {
4608            match serde_json::from_str::<crate::datadogV2::model::IncidentSearchResponse>(
4609                &local_content,
4610            ) {
4611                Ok(e) => {
4612                    return Ok(datadog::ResponseContent {
4613                        status: local_status,
4614                        content: local_content,
4615                        entity: Some(e),
4616                    })
4617                }
4618                Err(e) => return Err(datadog::Error::Serde(e)),
4619            };
4620        } else {
4621            let local_entity: Option<SearchIncidentsError> =
4622                serde_json::from_str(&local_content).ok();
4623            let local_error = datadog::ResponseContent {
4624                status: local_status,
4625                content: local_content,
4626                entity: local_entity,
4627            };
4628            Err(datadog::Error::ResponseError(local_error))
4629        }
4630    }
4631
4632    /// Updates an incident. Provide only the attributes that should be updated as this request is a partial update.
4633    pub async fn update_incident(
4634        &self,
4635        incident_id: String,
4636        body: crate::datadogV2::model::IncidentUpdateRequest,
4637        params: UpdateIncidentOptionalParams,
4638    ) -> Result<crate::datadogV2::model::IncidentResponse, datadog::Error<UpdateIncidentError>>
4639    {
4640        match self
4641            .update_incident_with_http_info(incident_id, body, params)
4642            .await
4643        {
4644            Ok(response_content) => {
4645                if let Some(e) = response_content.entity {
4646                    Ok(e)
4647                } else {
4648                    Err(datadog::Error::Serde(serde::de::Error::custom(
4649                        "response content was None",
4650                    )))
4651                }
4652            }
4653            Err(err) => Err(err),
4654        }
4655    }
4656
4657    /// Updates an incident. Provide only the attributes that should be updated as this request is a partial update.
4658    pub async fn update_incident_with_http_info(
4659        &self,
4660        incident_id: String,
4661        body: crate::datadogV2::model::IncidentUpdateRequest,
4662        params: UpdateIncidentOptionalParams,
4663    ) -> Result<
4664        datadog::ResponseContent<crate::datadogV2::model::IncidentResponse>,
4665        datadog::Error<UpdateIncidentError>,
4666    > {
4667        let local_configuration = &self.config;
4668        let operation_id = "v2.update_incident";
4669        if local_configuration.is_unstable_operation_enabled(operation_id) {
4670            warn!("Using unstable operation {operation_id}");
4671        } else {
4672            let local_error = datadog::UnstableOperationDisabledError {
4673                msg: "Operation 'v2.update_incident' is not enabled".to_string(),
4674            };
4675            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
4676        }
4677
4678        // unbox and build optional parameters
4679        let include = params.include;
4680
4681        let local_client = &self.client;
4682
4683        let local_uri_str = format!(
4684            "{}/api/v2/incidents/{incident_id}",
4685            local_configuration.get_operation_host(operation_id),
4686            incident_id = datadog::urlencode(incident_id)
4687        );
4688        let mut local_req_builder =
4689            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
4690
4691        if let Some(ref local) = include {
4692            local_req_builder = local_req_builder.query(&[(
4693                "include",
4694                &local
4695                    .iter()
4696                    .map(|p| p.to_string())
4697                    .collect::<Vec<String>>()
4698                    .join(",")
4699                    .to_string(),
4700            )]);
4701        };
4702
4703        // build headers
4704        let mut headers = HeaderMap::new();
4705        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
4706        headers.insert("Accept", HeaderValue::from_static("application/json"));
4707
4708        // build user agent
4709        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
4710            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
4711            Err(e) => {
4712                log::warn!("Failed to parse user agent header: {e}, falling back to default");
4713                headers.insert(
4714                    reqwest::header::USER_AGENT,
4715                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
4716                )
4717            }
4718        };
4719
4720        // build auth
4721        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
4722            headers.insert(
4723                "DD-API-KEY",
4724                HeaderValue::from_str(local_key.key.as_str())
4725                    .expect("failed to parse DD-API-KEY header"),
4726            );
4727        };
4728        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
4729            headers.insert(
4730                "DD-APPLICATION-KEY",
4731                HeaderValue::from_str(local_key.key.as_str())
4732                    .expect("failed to parse DD-APPLICATION-KEY header"),
4733            );
4734        };
4735
4736        // build body parameters
4737        let output = Vec::new();
4738        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
4739        if body.serialize(&mut ser).is_ok() {
4740            if let Some(content_encoding) = headers.get("Content-Encoding") {
4741                match content_encoding.to_str().unwrap_or_default() {
4742                    "gzip" => {
4743                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
4744                        let _ = enc.write_all(ser.into_inner().as_slice());
4745                        match enc.finish() {
4746                            Ok(buf) => {
4747                                local_req_builder = local_req_builder.body(buf);
4748                            }
4749                            Err(e) => return Err(datadog::Error::Io(e)),
4750                        }
4751                    }
4752                    "deflate" => {
4753                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
4754                        let _ = enc.write_all(ser.into_inner().as_slice());
4755                        match enc.finish() {
4756                            Ok(buf) => {
4757                                local_req_builder = local_req_builder.body(buf);
4758                            }
4759                            Err(e) => return Err(datadog::Error::Io(e)),
4760                        }
4761                    }
4762                    "zstd1" => {
4763                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
4764                        let _ = enc.write_all(ser.into_inner().as_slice());
4765                        match enc.finish() {
4766                            Ok(buf) => {
4767                                local_req_builder = local_req_builder.body(buf);
4768                            }
4769                            Err(e) => return Err(datadog::Error::Io(e)),
4770                        }
4771                    }
4772                    _ => {
4773                        local_req_builder = local_req_builder.body(ser.into_inner());
4774                    }
4775                }
4776            } else {
4777                local_req_builder = local_req_builder.body(ser.into_inner());
4778            }
4779        }
4780
4781        local_req_builder = local_req_builder.headers(headers);
4782        let local_req = local_req_builder.build()?;
4783        log::debug!("request content: {:?}", local_req.body());
4784        let local_resp = local_client.execute(local_req).await?;
4785
4786        let local_status = local_resp.status();
4787        let local_content = local_resp.text().await?;
4788        log::debug!("response content: {}", local_content);
4789
4790        if !local_status.is_client_error() && !local_status.is_server_error() {
4791            match serde_json::from_str::<crate::datadogV2::model::IncidentResponse>(&local_content)
4792            {
4793                Ok(e) => {
4794                    return Ok(datadog::ResponseContent {
4795                        status: local_status,
4796                        content: local_content,
4797                        entity: Some(e),
4798                    })
4799                }
4800                Err(e) => return Err(datadog::Error::Serde(e)),
4801            };
4802        } else {
4803            let local_entity: Option<UpdateIncidentError> =
4804                serde_json::from_str(&local_content).ok();
4805            let local_error = datadog::ResponseContent {
4806                status: local_status,
4807                content: local_content,
4808                entity: local_entity,
4809            };
4810            Err(datadog::Error::ResponseError(local_error))
4811        }
4812    }
4813
4814    /// The bulk update endpoint for creating, updating, and deleting attachments for a given incident.
4815    pub async fn update_incident_attachments(
4816        &self,
4817        incident_id: String,
4818        body: crate::datadogV2::model::IncidentAttachmentUpdateRequest,
4819        params: UpdateIncidentAttachmentsOptionalParams,
4820    ) -> Result<
4821        crate::datadogV2::model::IncidentAttachmentUpdateResponse,
4822        datadog::Error<UpdateIncidentAttachmentsError>,
4823    > {
4824        match self
4825            .update_incident_attachments_with_http_info(incident_id, body, params)
4826            .await
4827        {
4828            Ok(response_content) => {
4829                if let Some(e) = response_content.entity {
4830                    Ok(e)
4831                } else {
4832                    Err(datadog::Error::Serde(serde::de::Error::custom(
4833                        "response content was None",
4834                    )))
4835                }
4836            }
4837            Err(err) => Err(err),
4838        }
4839    }
4840
4841    /// The bulk update endpoint for creating, updating, and deleting attachments for a given incident.
4842    pub async fn update_incident_attachments_with_http_info(
4843        &self,
4844        incident_id: String,
4845        body: crate::datadogV2::model::IncidentAttachmentUpdateRequest,
4846        params: UpdateIncidentAttachmentsOptionalParams,
4847    ) -> Result<
4848        datadog::ResponseContent<crate::datadogV2::model::IncidentAttachmentUpdateResponse>,
4849        datadog::Error<UpdateIncidentAttachmentsError>,
4850    > {
4851        let local_configuration = &self.config;
4852        let operation_id = "v2.update_incident_attachments";
4853        if local_configuration.is_unstable_operation_enabled(operation_id) {
4854            warn!("Using unstable operation {operation_id}");
4855        } else {
4856            let local_error = datadog::UnstableOperationDisabledError {
4857                msg: "Operation 'v2.update_incident_attachments' is not enabled".to_string(),
4858            };
4859            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
4860        }
4861
4862        // unbox and build optional parameters
4863        let include = params.include;
4864
4865        let local_client = &self.client;
4866
4867        let local_uri_str = format!(
4868            "{}/api/v2/incidents/{incident_id}/attachments",
4869            local_configuration.get_operation_host(operation_id),
4870            incident_id = datadog::urlencode(incident_id)
4871        );
4872        let mut local_req_builder =
4873            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
4874
4875        if let Some(ref local) = include {
4876            local_req_builder = local_req_builder.query(&[(
4877                "include",
4878                &local
4879                    .iter()
4880                    .map(|p| p.to_string())
4881                    .collect::<Vec<String>>()
4882                    .join(",")
4883                    .to_string(),
4884            )]);
4885        };
4886
4887        // build headers
4888        let mut headers = HeaderMap::new();
4889        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
4890        headers.insert("Accept", HeaderValue::from_static("application/json"));
4891
4892        // build user agent
4893        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
4894            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
4895            Err(e) => {
4896                log::warn!("Failed to parse user agent header: {e}, falling back to default");
4897                headers.insert(
4898                    reqwest::header::USER_AGENT,
4899                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
4900                )
4901            }
4902        };
4903
4904        // build auth
4905        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
4906            headers.insert(
4907                "DD-API-KEY",
4908                HeaderValue::from_str(local_key.key.as_str())
4909                    .expect("failed to parse DD-API-KEY header"),
4910            );
4911        };
4912        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
4913            headers.insert(
4914                "DD-APPLICATION-KEY",
4915                HeaderValue::from_str(local_key.key.as_str())
4916                    .expect("failed to parse DD-APPLICATION-KEY header"),
4917            );
4918        };
4919
4920        // build body parameters
4921        let output = Vec::new();
4922        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
4923        if body.serialize(&mut ser).is_ok() {
4924            if let Some(content_encoding) = headers.get("Content-Encoding") {
4925                match content_encoding.to_str().unwrap_or_default() {
4926                    "gzip" => {
4927                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
4928                        let _ = enc.write_all(ser.into_inner().as_slice());
4929                        match enc.finish() {
4930                            Ok(buf) => {
4931                                local_req_builder = local_req_builder.body(buf);
4932                            }
4933                            Err(e) => return Err(datadog::Error::Io(e)),
4934                        }
4935                    }
4936                    "deflate" => {
4937                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
4938                        let _ = enc.write_all(ser.into_inner().as_slice());
4939                        match enc.finish() {
4940                            Ok(buf) => {
4941                                local_req_builder = local_req_builder.body(buf);
4942                            }
4943                            Err(e) => return Err(datadog::Error::Io(e)),
4944                        }
4945                    }
4946                    "zstd1" => {
4947                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
4948                        let _ = enc.write_all(ser.into_inner().as_slice());
4949                        match enc.finish() {
4950                            Ok(buf) => {
4951                                local_req_builder = local_req_builder.body(buf);
4952                            }
4953                            Err(e) => return Err(datadog::Error::Io(e)),
4954                        }
4955                    }
4956                    _ => {
4957                        local_req_builder = local_req_builder.body(ser.into_inner());
4958                    }
4959                }
4960            } else {
4961                local_req_builder = local_req_builder.body(ser.into_inner());
4962            }
4963        }
4964
4965        local_req_builder = local_req_builder.headers(headers);
4966        let local_req = local_req_builder.build()?;
4967        log::debug!("request content: {:?}", local_req.body());
4968        let local_resp = local_client.execute(local_req).await?;
4969
4970        let local_status = local_resp.status();
4971        let local_content = local_resp.text().await?;
4972        log::debug!("response content: {}", local_content);
4973
4974        if !local_status.is_client_error() && !local_status.is_server_error() {
4975            match serde_json::from_str::<crate::datadogV2::model::IncidentAttachmentUpdateResponse>(
4976                &local_content,
4977            ) {
4978                Ok(e) => {
4979                    return Ok(datadog::ResponseContent {
4980                        status: local_status,
4981                        content: local_content,
4982                        entity: Some(e),
4983                    })
4984                }
4985                Err(e) => return Err(datadog::Error::Serde(e)),
4986            };
4987        } else {
4988            let local_entity: Option<UpdateIncidentAttachmentsError> =
4989                serde_json::from_str(&local_content).ok();
4990            let local_error = datadog::ResponseContent {
4991                status: local_status,
4992                content: local_content,
4993                entity: local_entity,
4994            };
4995            Err(datadog::Error::ResponseError(local_error))
4996        }
4997    }
4998
4999    /// Update an existing incident integration metadata.
5000    pub async fn update_incident_integration(
5001        &self,
5002        incident_id: String,
5003        integration_metadata_id: String,
5004        body: crate::datadogV2::model::IncidentIntegrationMetadataPatchRequest,
5005    ) -> Result<
5006        crate::datadogV2::model::IncidentIntegrationMetadataResponse,
5007        datadog::Error<UpdateIncidentIntegrationError>,
5008    > {
5009        match self
5010            .update_incident_integration_with_http_info(incident_id, integration_metadata_id, body)
5011            .await
5012        {
5013            Ok(response_content) => {
5014                if let Some(e) = response_content.entity {
5015                    Ok(e)
5016                } else {
5017                    Err(datadog::Error::Serde(serde::de::Error::custom(
5018                        "response content was None",
5019                    )))
5020                }
5021            }
5022            Err(err) => Err(err),
5023        }
5024    }
5025
5026    /// Update an existing incident integration metadata.
5027    pub async fn update_incident_integration_with_http_info(
5028        &self,
5029        incident_id: String,
5030        integration_metadata_id: String,
5031        body: crate::datadogV2::model::IncidentIntegrationMetadataPatchRequest,
5032    ) -> Result<
5033        datadog::ResponseContent<crate::datadogV2::model::IncidentIntegrationMetadataResponse>,
5034        datadog::Error<UpdateIncidentIntegrationError>,
5035    > {
5036        let local_configuration = &self.config;
5037        let operation_id = "v2.update_incident_integration";
5038        if local_configuration.is_unstable_operation_enabled(operation_id) {
5039            warn!("Using unstable operation {operation_id}");
5040        } else {
5041            let local_error = datadog::UnstableOperationDisabledError {
5042                msg: "Operation 'v2.update_incident_integration' is not enabled".to_string(),
5043            };
5044            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
5045        }
5046
5047        let local_client = &self.client;
5048
5049        let local_uri_str = format!(
5050            "{}/api/v2/incidents/{incident_id}/relationships/integrations/{integration_metadata_id}",
5051            local_configuration.get_operation_host(operation_id), incident_id=
5052            datadog::urlencode(incident_id)
5053            , integration_metadata_id=
5054            datadog::urlencode(integration_metadata_id)
5055            );
5056        let mut local_req_builder =
5057            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
5058
5059        // build headers
5060        let mut headers = HeaderMap::new();
5061        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
5062        headers.insert("Accept", HeaderValue::from_static("application/json"));
5063
5064        // build user agent
5065        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
5066            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
5067            Err(e) => {
5068                log::warn!("Failed to parse user agent header: {e}, falling back to default");
5069                headers.insert(
5070                    reqwest::header::USER_AGENT,
5071                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
5072                )
5073            }
5074        };
5075
5076        // build auth
5077        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
5078            headers.insert(
5079                "DD-API-KEY",
5080                HeaderValue::from_str(local_key.key.as_str())
5081                    .expect("failed to parse DD-API-KEY header"),
5082            );
5083        };
5084        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
5085            headers.insert(
5086                "DD-APPLICATION-KEY",
5087                HeaderValue::from_str(local_key.key.as_str())
5088                    .expect("failed to parse DD-APPLICATION-KEY header"),
5089            );
5090        };
5091
5092        // build body parameters
5093        let output = Vec::new();
5094        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
5095        if body.serialize(&mut ser).is_ok() {
5096            if let Some(content_encoding) = headers.get("Content-Encoding") {
5097                match content_encoding.to_str().unwrap_or_default() {
5098                    "gzip" => {
5099                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
5100                        let _ = enc.write_all(ser.into_inner().as_slice());
5101                        match enc.finish() {
5102                            Ok(buf) => {
5103                                local_req_builder = local_req_builder.body(buf);
5104                            }
5105                            Err(e) => return Err(datadog::Error::Io(e)),
5106                        }
5107                    }
5108                    "deflate" => {
5109                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
5110                        let _ = enc.write_all(ser.into_inner().as_slice());
5111                        match enc.finish() {
5112                            Ok(buf) => {
5113                                local_req_builder = local_req_builder.body(buf);
5114                            }
5115                            Err(e) => return Err(datadog::Error::Io(e)),
5116                        }
5117                    }
5118                    "zstd1" => {
5119                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
5120                        let _ = enc.write_all(ser.into_inner().as_slice());
5121                        match enc.finish() {
5122                            Ok(buf) => {
5123                                local_req_builder = local_req_builder.body(buf);
5124                            }
5125                            Err(e) => return Err(datadog::Error::Io(e)),
5126                        }
5127                    }
5128                    _ => {
5129                        local_req_builder = local_req_builder.body(ser.into_inner());
5130                    }
5131                }
5132            } else {
5133                local_req_builder = local_req_builder.body(ser.into_inner());
5134            }
5135        }
5136
5137        local_req_builder = local_req_builder.headers(headers);
5138        let local_req = local_req_builder.build()?;
5139        log::debug!("request content: {:?}", local_req.body());
5140        let local_resp = local_client.execute(local_req).await?;
5141
5142        let local_status = local_resp.status();
5143        let local_content = local_resp.text().await?;
5144        log::debug!("response content: {}", local_content);
5145
5146        if !local_status.is_client_error() && !local_status.is_server_error() {
5147            match serde_json::from_str::<crate::datadogV2::model::IncidentIntegrationMetadataResponse>(
5148                &local_content,
5149            ) {
5150                Ok(e) => {
5151                    return Ok(datadog::ResponseContent {
5152                        status: local_status,
5153                        content: local_content,
5154                        entity: Some(e),
5155                    })
5156                }
5157                Err(e) => return Err(datadog::Error::Serde(e)),
5158            };
5159        } else {
5160            let local_entity: Option<UpdateIncidentIntegrationError> =
5161                serde_json::from_str(&local_content).ok();
5162            let local_error = datadog::ResponseContent {
5163                status: local_status,
5164                content: local_content,
5165                entity: local_entity,
5166            };
5167            Err(datadog::Error::ResponseError(local_error))
5168        }
5169    }
5170
5171    /// Updates an existing notification rule with a complete replacement.
5172    pub async fn update_incident_notification_rule(
5173        &self,
5174        id: uuid::Uuid,
5175        body: crate::datadogV2::model::PutIncidentNotificationRuleRequest,
5176        params: UpdateIncidentNotificationRuleOptionalParams,
5177    ) -> Result<
5178        crate::datadogV2::model::IncidentNotificationRule,
5179        datadog::Error<UpdateIncidentNotificationRuleError>,
5180    > {
5181        match self
5182            .update_incident_notification_rule_with_http_info(id, body, params)
5183            .await
5184        {
5185            Ok(response_content) => {
5186                if let Some(e) = response_content.entity {
5187                    Ok(e)
5188                } else {
5189                    Err(datadog::Error::Serde(serde::de::Error::custom(
5190                        "response content was None",
5191                    )))
5192                }
5193            }
5194            Err(err) => Err(err),
5195        }
5196    }
5197
5198    /// Updates an existing notification rule with a complete replacement.
5199    pub async fn update_incident_notification_rule_with_http_info(
5200        &self,
5201        id: uuid::Uuid,
5202        body: crate::datadogV2::model::PutIncidentNotificationRuleRequest,
5203        params: UpdateIncidentNotificationRuleOptionalParams,
5204    ) -> Result<
5205        datadog::ResponseContent<crate::datadogV2::model::IncidentNotificationRule>,
5206        datadog::Error<UpdateIncidentNotificationRuleError>,
5207    > {
5208        let local_configuration = &self.config;
5209        let operation_id = "v2.update_incident_notification_rule";
5210        if local_configuration.is_unstable_operation_enabled(operation_id) {
5211            warn!("Using unstable operation {operation_id}");
5212        } else {
5213            let local_error = datadog::UnstableOperationDisabledError {
5214                msg: "Operation 'v2.update_incident_notification_rule' is not enabled".to_string(),
5215            };
5216            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
5217        }
5218
5219        // unbox and build optional parameters
5220        let include = params.include;
5221
5222        let local_client = &self.client;
5223
5224        let local_uri_str = format!(
5225            "{}/api/v2/incidents/config/notification-rules/{id}",
5226            local_configuration.get_operation_host(operation_id),
5227            id = datadog::urlencode(id.to_string())
5228        );
5229        let mut local_req_builder =
5230            local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
5231
5232        if let Some(ref local_query_param) = include {
5233            local_req_builder =
5234                local_req_builder.query(&[("include", &local_query_param.to_string())]);
5235        };
5236
5237        // build headers
5238        let mut headers = HeaderMap::new();
5239        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
5240        headers.insert("Accept", HeaderValue::from_static("application/json"));
5241
5242        // build user agent
5243        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
5244            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
5245            Err(e) => {
5246                log::warn!("Failed to parse user agent header: {e}, falling back to default");
5247                headers.insert(
5248                    reqwest::header::USER_AGENT,
5249                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
5250                )
5251            }
5252        };
5253
5254        // build auth
5255        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
5256            headers.insert(
5257                "DD-API-KEY",
5258                HeaderValue::from_str(local_key.key.as_str())
5259                    .expect("failed to parse DD-API-KEY header"),
5260            );
5261        };
5262        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
5263            headers.insert(
5264                "DD-APPLICATION-KEY",
5265                HeaderValue::from_str(local_key.key.as_str())
5266                    .expect("failed to parse DD-APPLICATION-KEY header"),
5267            );
5268        };
5269
5270        // build body parameters
5271        let output = Vec::new();
5272        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
5273        if body.serialize(&mut ser).is_ok() {
5274            if let Some(content_encoding) = headers.get("Content-Encoding") {
5275                match content_encoding.to_str().unwrap_or_default() {
5276                    "gzip" => {
5277                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
5278                        let _ = enc.write_all(ser.into_inner().as_slice());
5279                        match enc.finish() {
5280                            Ok(buf) => {
5281                                local_req_builder = local_req_builder.body(buf);
5282                            }
5283                            Err(e) => return Err(datadog::Error::Io(e)),
5284                        }
5285                    }
5286                    "deflate" => {
5287                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
5288                        let _ = enc.write_all(ser.into_inner().as_slice());
5289                        match enc.finish() {
5290                            Ok(buf) => {
5291                                local_req_builder = local_req_builder.body(buf);
5292                            }
5293                            Err(e) => return Err(datadog::Error::Io(e)),
5294                        }
5295                    }
5296                    "zstd1" => {
5297                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
5298                        let _ = enc.write_all(ser.into_inner().as_slice());
5299                        match enc.finish() {
5300                            Ok(buf) => {
5301                                local_req_builder = local_req_builder.body(buf);
5302                            }
5303                            Err(e) => return Err(datadog::Error::Io(e)),
5304                        }
5305                    }
5306                    _ => {
5307                        local_req_builder = local_req_builder.body(ser.into_inner());
5308                    }
5309                }
5310            } else {
5311                local_req_builder = local_req_builder.body(ser.into_inner());
5312            }
5313        }
5314
5315        local_req_builder = local_req_builder.headers(headers);
5316        let local_req = local_req_builder.build()?;
5317        log::debug!("request content: {:?}", local_req.body());
5318        let local_resp = local_client.execute(local_req).await?;
5319
5320        let local_status = local_resp.status();
5321        let local_content = local_resp.text().await?;
5322        log::debug!("response content: {}", local_content);
5323
5324        if !local_status.is_client_error() && !local_status.is_server_error() {
5325            match serde_json::from_str::<crate::datadogV2::model::IncidentNotificationRule>(
5326                &local_content,
5327            ) {
5328                Ok(e) => {
5329                    return Ok(datadog::ResponseContent {
5330                        status: local_status,
5331                        content: local_content,
5332                        entity: Some(e),
5333                    })
5334                }
5335                Err(e) => return Err(datadog::Error::Serde(e)),
5336            };
5337        } else {
5338            let local_entity: Option<UpdateIncidentNotificationRuleError> =
5339                serde_json::from_str(&local_content).ok();
5340            let local_error = datadog::ResponseContent {
5341                status: local_status,
5342                content: local_content,
5343                entity: local_entity,
5344            };
5345            Err(datadog::Error::ResponseError(local_error))
5346        }
5347    }
5348
5349    /// Updates an existing notification template's attributes.
5350    pub async fn update_incident_notification_template(
5351        &self,
5352        id: uuid::Uuid,
5353        body: crate::datadogV2::model::PatchIncidentNotificationTemplateRequest,
5354        params: UpdateIncidentNotificationTemplateOptionalParams,
5355    ) -> Result<
5356        crate::datadogV2::model::IncidentNotificationTemplate,
5357        datadog::Error<UpdateIncidentNotificationTemplateError>,
5358    > {
5359        match self
5360            .update_incident_notification_template_with_http_info(id, body, params)
5361            .await
5362        {
5363            Ok(response_content) => {
5364                if let Some(e) = response_content.entity {
5365                    Ok(e)
5366                } else {
5367                    Err(datadog::Error::Serde(serde::de::Error::custom(
5368                        "response content was None",
5369                    )))
5370                }
5371            }
5372            Err(err) => Err(err),
5373        }
5374    }
5375
5376    /// Updates an existing notification template's attributes.
5377    pub async fn update_incident_notification_template_with_http_info(
5378        &self,
5379        id: uuid::Uuid,
5380        body: crate::datadogV2::model::PatchIncidentNotificationTemplateRequest,
5381        params: UpdateIncidentNotificationTemplateOptionalParams,
5382    ) -> Result<
5383        datadog::ResponseContent<crate::datadogV2::model::IncidentNotificationTemplate>,
5384        datadog::Error<UpdateIncidentNotificationTemplateError>,
5385    > {
5386        let local_configuration = &self.config;
5387        let operation_id = "v2.update_incident_notification_template";
5388        if local_configuration.is_unstable_operation_enabled(operation_id) {
5389            warn!("Using unstable operation {operation_id}");
5390        } else {
5391            let local_error = datadog::UnstableOperationDisabledError {
5392                msg: "Operation 'v2.update_incident_notification_template' is not enabled"
5393                    .to_string(),
5394            };
5395            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
5396        }
5397
5398        // unbox and build optional parameters
5399        let include = params.include;
5400
5401        let local_client = &self.client;
5402
5403        let local_uri_str = format!(
5404            "{}/api/v2/incidents/config/notification-templates/{id}",
5405            local_configuration.get_operation_host(operation_id),
5406            id = datadog::urlencode(id.to_string())
5407        );
5408        let mut local_req_builder =
5409            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
5410
5411        if let Some(ref local_query_param) = include {
5412            local_req_builder =
5413                local_req_builder.query(&[("include", &local_query_param.to_string())]);
5414        };
5415
5416        // build headers
5417        let mut headers = HeaderMap::new();
5418        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
5419        headers.insert("Accept", HeaderValue::from_static("application/json"));
5420
5421        // build user agent
5422        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
5423            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
5424            Err(e) => {
5425                log::warn!("Failed to parse user agent header: {e}, falling back to default");
5426                headers.insert(
5427                    reqwest::header::USER_AGENT,
5428                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
5429                )
5430            }
5431        };
5432
5433        // build auth
5434        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
5435            headers.insert(
5436                "DD-API-KEY",
5437                HeaderValue::from_str(local_key.key.as_str())
5438                    .expect("failed to parse DD-API-KEY header"),
5439            );
5440        };
5441        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
5442            headers.insert(
5443                "DD-APPLICATION-KEY",
5444                HeaderValue::from_str(local_key.key.as_str())
5445                    .expect("failed to parse DD-APPLICATION-KEY header"),
5446            );
5447        };
5448
5449        // build body parameters
5450        let output = Vec::new();
5451        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
5452        if body.serialize(&mut ser).is_ok() {
5453            if let Some(content_encoding) = headers.get("Content-Encoding") {
5454                match content_encoding.to_str().unwrap_or_default() {
5455                    "gzip" => {
5456                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
5457                        let _ = enc.write_all(ser.into_inner().as_slice());
5458                        match enc.finish() {
5459                            Ok(buf) => {
5460                                local_req_builder = local_req_builder.body(buf);
5461                            }
5462                            Err(e) => return Err(datadog::Error::Io(e)),
5463                        }
5464                    }
5465                    "deflate" => {
5466                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
5467                        let _ = enc.write_all(ser.into_inner().as_slice());
5468                        match enc.finish() {
5469                            Ok(buf) => {
5470                                local_req_builder = local_req_builder.body(buf);
5471                            }
5472                            Err(e) => return Err(datadog::Error::Io(e)),
5473                        }
5474                    }
5475                    "zstd1" => {
5476                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
5477                        let _ = enc.write_all(ser.into_inner().as_slice());
5478                        match enc.finish() {
5479                            Ok(buf) => {
5480                                local_req_builder = local_req_builder.body(buf);
5481                            }
5482                            Err(e) => return Err(datadog::Error::Io(e)),
5483                        }
5484                    }
5485                    _ => {
5486                        local_req_builder = local_req_builder.body(ser.into_inner());
5487                    }
5488                }
5489            } else {
5490                local_req_builder = local_req_builder.body(ser.into_inner());
5491            }
5492        }
5493
5494        local_req_builder = local_req_builder.headers(headers);
5495        let local_req = local_req_builder.build()?;
5496        log::debug!("request content: {:?}", local_req.body());
5497        let local_resp = local_client.execute(local_req).await?;
5498
5499        let local_status = local_resp.status();
5500        let local_content = local_resp.text().await?;
5501        log::debug!("response content: {}", local_content);
5502
5503        if !local_status.is_client_error() && !local_status.is_server_error() {
5504            match serde_json::from_str::<crate::datadogV2::model::IncidentNotificationTemplate>(
5505                &local_content,
5506            ) {
5507                Ok(e) => {
5508                    return Ok(datadog::ResponseContent {
5509                        status: local_status,
5510                        content: local_content,
5511                        entity: Some(e),
5512                    })
5513                }
5514                Err(e) => return Err(datadog::Error::Serde(e)),
5515            };
5516        } else {
5517            let local_entity: Option<UpdateIncidentNotificationTemplateError> =
5518                serde_json::from_str(&local_content).ok();
5519            let local_error = datadog::ResponseContent {
5520                status: local_status,
5521                content: local_content,
5522                entity: local_entity,
5523            };
5524            Err(datadog::Error::ResponseError(local_error))
5525        }
5526    }
5527
5528    /// Update an incident todo.
5529    pub async fn update_incident_todo(
5530        &self,
5531        incident_id: String,
5532        todo_id: String,
5533        body: crate::datadogV2::model::IncidentTodoPatchRequest,
5534    ) -> Result<
5535        crate::datadogV2::model::IncidentTodoResponse,
5536        datadog::Error<UpdateIncidentTodoError>,
5537    > {
5538        match self
5539            .update_incident_todo_with_http_info(incident_id, todo_id, body)
5540            .await
5541        {
5542            Ok(response_content) => {
5543                if let Some(e) = response_content.entity {
5544                    Ok(e)
5545                } else {
5546                    Err(datadog::Error::Serde(serde::de::Error::custom(
5547                        "response content was None",
5548                    )))
5549                }
5550            }
5551            Err(err) => Err(err),
5552        }
5553    }
5554
5555    /// Update an incident todo.
5556    pub async fn update_incident_todo_with_http_info(
5557        &self,
5558        incident_id: String,
5559        todo_id: String,
5560        body: crate::datadogV2::model::IncidentTodoPatchRequest,
5561    ) -> Result<
5562        datadog::ResponseContent<crate::datadogV2::model::IncidentTodoResponse>,
5563        datadog::Error<UpdateIncidentTodoError>,
5564    > {
5565        let local_configuration = &self.config;
5566        let operation_id = "v2.update_incident_todo";
5567        if local_configuration.is_unstable_operation_enabled(operation_id) {
5568            warn!("Using unstable operation {operation_id}");
5569        } else {
5570            let local_error = datadog::UnstableOperationDisabledError {
5571                msg: "Operation 'v2.update_incident_todo' is not enabled".to_string(),
5572            };
5573            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
5574        }
5575
5576        let local_client = &self.client;
5577
5578        let local_uri_str = format!(
5579            "{}/api/v2/incidents/{incident_id}/relationships/todos/{todo_id}",
5580            local_configuration.get_operation_host(operation_id),
5581            incident_id = datadog::urlencode(incident_id),
5582            todo_id = datadog::urlencode(todo_id)
5583        );
5584        let mut local_req_builder =
5585            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
5586
5587        // build headers
5588        let mut headers = HeaderMap::new();
5589        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
5590        headers.insert("Accept", HeaderValue::from_static("application/json"));
5591
5592        // build user agent
5593        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
5594            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
5595            Err(e) => {
5596                log::warn!("Failed to parse user agent header: {e}, falling back to default");
5597                headers.insert(
5598                    reqwest::header::USER_AGENT,
5599                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
5600                )
5601            }
5602        };
5603
5604        // build auth
5605        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
5606            headers.insert(
5607                "DD-API-KEY",
5608                HeaderValue::from_str(local_key.key.as_str())
5609                    .expect("failed to parse DD-API-KEY header"),
5610            );
5611        };
5612        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
5613            headers.insert(
5614                "DD-APPLICATION-KEY",
5615                HeaderValue::from_str(local_key.key.as_str())
5616                    .expect("failed to parse DD-APPLICATION-KEY header"),
5617            );
5618        };
5619
5620        // build body parameters
5621        let output = Vec::new();
5622        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
5623        if body.serialize(&mut ser).is_ok() {
5624            if let Some(content_encoding) = headers.get("Content-Encoding") {
5625                match content_encoding.to_str().unwrap_or_default() {
5626                    "gzip" => {
5627                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
5628                        let _ = enc.write_all(ser.into_inner().as_slice());
5629                        match enc.finish() {
5630                            Ok(buf) => {
5631                                local_req_builder = local_req_builder.body(buf);
5632                            }
5633                            Err(e) => return Err(datadog::Error::Io(e)),
5634                        }
5635                    }
5636                    "deflate" => {
5637                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
5638                        let _ = enc.write_all(ser.into_inner().as_slice());
5639                        match enc.finish() {
5640                            Ok(buf) => {
5641                                local_req_builder = local_req_builder.body(buf);
5642                            }
5643                            Err(e) => return Err(datadog::Error::Io(e)),
5644                        }
5645                    }
5646                    "zstd1" => {
5647                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
5648                        let _ = enc.write_all(ser.into_inner().as_slice());
5649                        match enc.finish() {
5650                            Ok(buf) => {
5651                                local_req_builder = local_req_builder.body(buf);
5652                            }
5653                            Err(e) => return Err(datadog::Error::Io(e)),
5654                        }
5655                    }
5656                    _ => {
5657                        local_req_builder = local_req_builder.body(ser.into_inner());
5658                    }
5659                }
5660            } else {
5661                local_req_builder = local_req_builder.body(ser.into_inner());
5662            }
5663        }
5664
5665        local_req_builder = local_req_builder.headers(headers);
5666        let local_req = local_req_builder.build()?;
5667        log::debug!("request content: {:?}", local_req.body());
5668        let local_resp = local_client.execute(local_req).await?;
5669
5670        let local_status = local_resp.status();
5671        let local_content = local_resp.text().await?;
5672        log::debug!("response content: {}", local_content);
5673
5674        if !local_status.is_client_error() && !local_status.is_server_error() {
5675            match serde_json::from_str::<crate::datadogV2::model::IncidentTodoResponse>(
5676                &local_content,
5677            ) {
5678                Ok(e) => {
5679                    return Ok(datadog::ResponseContent {
5680                        status: local_status,
5681                        content: local_content,
5682                        entity: Some(e),
5683                    })
5684                }
5685                Err(e) => return Err(datadog::Error::Serde(e)),
5686            };
5687        } else {
5688            let local_entity: Option<UpdateIncidentTodoError> =
5689                serde_json::from_str(&local_content).ok();
5690            let local_error = datadog::ResponseContent {
5691                status: local_status,
5692                content: local_content,
5693                entity: local_entity,
5694            };
5695            Err(datadog::Error::ResponseError(local_error))
5696        }
5697    }
5698
5699    /// Update an incident type.
5700    pub async fn update_incident_type(
5701        &self,
5702        incident_type_id: String,
5703        body: crate::datadogV2::model::IncidentTypePatchRequest,
5704    ) -> Result<
5705        crate::datadogV2::model::IncidentTypeResponse,
5706        datadog::Error<UpdateIncidentTypeError>,
5707    > {
5708        match self
5709            .update_incident_type_with_http_info(incident_type_id, body)
5710            .await
5711        {
5712            Ok(response_content) => {
5713                if let Some(e) = response_content.entity {
5714                    Ok(e)
5715                } else {
5716                    Err(datadog::Error::Serde(serde::de::Error::custom(
5717                        "response content was None",
5718                    )))
5719                }
5720            }
5721            Err(err) => Err(err),
5722        }
5723    }
5724
5725    /// Update an incident type.
5726    pub async fn update_incident_type_with_http_info(
5727        &self,
5728        incident_type_id: String,
5729        body: crate::datadogV2::model::IncidentTypePatchRequest,
5730    ) -> Result<
5731        datadog::ResponseContent<crate::datadogV2::model::IncidentTypeResponse>,
5732        datadog::Error<UpdateIncidentTypeError>,
5733    > {
5734        let local_configuration = &self.config;
5735        let operation_id = "v2.update_incident_type";
5736        if local_configuration.is_unstable_operation_enabled(operation_id) {
5737            warn!("Using unstable operation {operation_id}");
5738        } else {
5739            let local_error = datadog::UnstableOperationDisabledError {
5740                msg: "Operation 'v2.update_incident_type' is not enabled".to_string(),
5741            };
5742            return Err(datadog::Error::UnstableOperationDisabledError(local_error));
5743        }
5744
5745        let local_client = &self.client;
5746
5747        let local_uri_str = format!(
5748            "{}/api/v2/incidents/config/types/{incident_type_id}",
5749            local_configuration.get_operation_host(operation_id),
5750            incident_type_id = datadog::urlencode(incident_type_id)
5751        );
5752        let mut local_req_builder =
5753            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
5754
5755        // build headers
5756        let mut headers = HeaderMap::new();
5757        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
5758        headers.insert("Accept", HeaderValue::from_static("application/json"));
5759
5760        // build user agent
5761        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
5762            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
5763            Err(e) => {
5764                log::warn!("Failed to parse user agent header: {e}, falling back to default");
5765                headers.insert(
5766                    reqwest::header::USER_AGENT,
5767                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
5768                )
5769            }
5770        };
5771
5772        // build auth
5773        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
5774            headers.insert(
5775                "DD-API-KEY",
5776                HeaderValue::from_str(local_key.key.as_str())
5777                    .expect("failed to parse DD-API-KEY header"),
5778            );
5779        };
5780        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
5781            headers.insert(
5782                "DD-APPLICATION-KEY",
5783                HeaderValue::from_str(local_key.key.as_str())
5784                    .expect("failed to parse DD-APPLICATION-KEY header"),
5785            );
5786        };
5787
5788        // build body parameters
5789        let output = Vec::new();
5790        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
5791        if body.serialize(&mut ser).is_ok() {
5792            if let Some(content_encoding) = headers.get("Content-Encoding") {
5793                match content_encoding.to_str().unwrap_or_default() {
5794                    "gzip" => {
5795                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
5796                        let _ = enc.write_all(ser.into_inner().as_slice());
5797                        match enc.finish() {
5798                            Ok(buf) => {
5799                                local_req_builder = local_req_builder.body(buf);
5800                            }
5801                            Err(e) => return Err(datadog::Error::Io(e)),
5802                        }
5803                    }
5804                    "deflate" => {
5805                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
5806                        let _ = enc.write_all(ser.into_inner().as_slice());
5807                        match enc.finish() {
5808                            Ok(buf) => {
5809                                local_req_builder = local_req_builder.body(buf);
5810                            }
5811                            Err(e) => return Err(datadog::Error::Io(e)),
5812                        }
5813                    }
5814                    "zstd1" => {
5815                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
5816                        let _ = enc.write_all(ser.into_inner().as_slice());
5817                        match enc.finish() {
5818                            Ok(buf) => {
5819                                local_req_builder = local_req_builder.body(buf);
5820                            }
5821                            Err(e) => return Err(datadog::Error::Io(e)),
5822                        }
5823                    }
5824                    _ => {
5825                        local_req_builder = local_req_builder.body(ser.into_inner());
5826                    }
5827                }
5828            } else {
5829                local_req_builder = local_req_builder.body(ser.into_inner());
5830            }
5831        }
5832
5833        local_req_builder = local_req_builder.headers(headers);
5834        let local_req = local_req_builder.build()?;
5835        log::debug!("request content: {:?}", local_req.body());
5836        let local_resp = local_client.execute(local_req).await?;
5837
5838        let local_status = local_resp.status();
5839        let local_content = local_resp.text().await?;
5840        log::debug!("response content: {}", local_content);
5841
5842        if !local_status.is_client_error() && !local_status.is_server_error() {
5843            match serde_json::from_str::<crate::datadogV2::model::IncidentTypeResponse>(
5844                &local_content,
5845            ) {
5846                Ok(e) => {
5847                    return Ok(datadog::ResponseContent {
5848                        status: local_status,
5849                        content: local_content,
5850                        entity: Some(e),
5851                    })
5852                }
5853                Err(e) => return Err(datadog::Error::Serde(e)),
5854            };
5855        } else {
5856            let local_entity: Option<UpdateIncidentTypeError> =
5857                serde_json::from_str(&local_content).ok();
5858            let local_error = datadog::ResponseContent {
5859                status: local_status,
5860                content: local_content,
5861                entity: local_entity,
5862            };
5863            Err(datadog::Error::ResponseError(local_error))
5864        }
5865    }
5866}