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