datadog_api_client/datadogV2/model/
model_ci_app_query_options.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 serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// Global query options that are used during the query.
10/// Only supply timezone or time offset, not both. Otherwise, the query fails.
11#[non_exhaustive]
12#[skip_serializing_none]
13#[derive(Clone, Debug, PartialEq, Serialize)]
14pub struct CIAppQueryOptions {
15    /// The time offset (in seconds) to apply to the query.
16    #[serde(rename = "time_offset")]
17    pub time_offset: Option<i64>,
18    /// The timezone can be specified as GMT, UTC, an offset from UTC (like UTC+1), or as a Timezone Database identifier (like America/New_York).
19    #[serde(rename = "timezone")]
20    pub timezone: Option<String>,
21    #[serde(flatten)]
22    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
23    #[serde(skip)]
24    #[serde(default)]
25    pub(crate) _unparsed: bool,
26}
27
28impl CIAppQueryOptions {
29    pub fn new() -> CIAppQueryOptions {
30        CIAppQueryOptions {
31            time_offset: None,
32            timezone: None,
33            additional_properties: std::collections::BTreeMap::new(),
34            _unparsed: false,
35        }
36    }
37
38    pub fn time_offset(mut self, value: i64) -> Self {
39        self.time_offset = Some(value);
40        self
41    }
42
43    pub fn timezone(mut self, value: String) -> Self {
44        self.timezone = Some(value);
45        self
46    }
47
48    pub fn additional_properties(
49        mut self,
50        value: std::collections::BTreeMap<String, serde_json::Value>,
51    ) -> Self {
52        self.additional_properties = value;
53        self
54    }
55}
56
57impl Default for CIAppQueryOptions {
58    fn default() -> Self {
59        Self::new()
60    }
61}
62
63impl<'de> Deserialize<'de> for CIAppQueryOptions {
64    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
65    where
66        D: Deserializer<'de>,
67    {
68        struct CIAppQueryOptionsVisitor;
69        impl<'a> Visitor<'a> for CIAppQueryOptionsVisitor {
70            type Value = CIAppQueryOptions;
71
72            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
73                f.write_str("a mapping")
74            }
75
76            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
77            where
78                M: MapAccess<'a>,
79            {
80                let mut time_offset: Option<i64> = None;
81                let mut timezone: Option<String> = None;
82                let mut additional_properties: std::collections::BTreeMap<
83                    String,
84                    serde_json::Value,
85                > = std::collections::BTreeMap::new();
86                let mut _unparsed = false;
87
88                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
89                    match k.as_str() {
90                        "time_offset" => {
91                            if v.is_null() {
92                                continue;
93                            }
94                            time_offset =
95                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
96                        }
97                        "timezone" => {
98                            if v.is_null() {
99                                continue;
100                            }
101                            timezone = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
102                        }
103                        &_ => {
104                            if let Ok(value) = serde_json::from_value(v.clone()) {
105                                additional_properties.insert(k, value);
106                            }
107                        }
108                    }
109                }
110
111                let content = CIAppQueryOptions {
112                    time_offset,
113                    timezone,
114                    additional_properties,
115                    _unparsed,
116                };
117
118                Ok(content)
119            }
120        }
121
122        deserializer.deserialize_any(CIAppQueryOptionsVisitor)
123    }
124}