datadog_api_client/datadogV2/api/
api_cloud_cost_management.rs

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