datadog_api_client/datadogV2/model/
model_case_assign_attributes.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/// Case assign attributes
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CaseAssignAttributes {
14    /// Assignee's UUID
15    #[serde(rename = "assignee_id")]
16    pub assignee_id: String,
17    #[serde(flatten)]
18    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
19    #[serde(skip)]
20    #[serde(default)]
21    pub(crate) _unparsed: bool,
22}
23
24impl CaseAssignAttributes {
25    pub fn new(assignee_id: String) -> CaseAssignAttributes {
26        CaseAssignAttributes {
27            assignee_id,
28            additional_properties: std::collections::BTreeMap::new(),
29            _unparsed: false,
30        }
31    }
32
33    pub fn additional_properties(
34        mut self,
35        value: std::collections::BTreeMap<String, serde_json::Value>,
36    ) -> Self {
37        self.additional_properties = value;
38        self
39    }
40}
41
42impl<'de> Deserialize<'de> for CaseAssignAttributes {
43    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
44    where
45        D: Deserializer<'de>,
46    {
47        struct CaseAssignAttributesVisitor;
48        impl<'a> Visitor<'a> for CaseAssignAttributesVisitor {
49            type Value = CaseAssignAttributes;
50
51            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
52                f.write_str("a mapping")
53            }
54
55            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
56            where
57                M: MapAccess<'a>,
58            {
59                let mut assignee_id: Option<String> = None;
60                let mut additional_properties: std::collections::BTreeMap<
61                    String,
62                    serde_json::Value,
63                > = std::collections::BTreeMap::new();
64                let mut _unparsed = false;
65
66                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
67                    match k.as_str() {
68                        "assignee_id" => {
69                            assignee_id =
70                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
71                        }
72                        &_ => {
73                            if let Ok(value) = serde_json::from_value(v.clone()) {
74                                additional_properties.insert(k, value);
75                            }
76                        }
77                    }
78                }
79                let assignee_id =
80                    assignee_id.ok_or_else(|| M::Error::missing_field("assignee_id"))?;
81
82                let content = CaseAssignAttributes {
83                    assignee_id,
84                    additional_properties,
85                    _unparsed,
86                };
87
88                Ok(content)
89            }
90        }
91
92        deserializer.deserialize_any(CaseAssignAttributesVisitor)
93    }
94}