things3_cloud/wire/
area.rs1use crate::ids::ThingsId;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::collections::BTreeMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
8pub struct AreaProps {
9 #[serde(rename = "tt", default)]
11 pub title: String,
12
13 #[serde(rename = "tg", default)]
15 pub tag_ids: Vec<ThingsId>,
16
17 #[serde(rename = "ix", default)]
19 pub sort_index: i32,
20
21 #[serde(rename = "xx", default)]
23 pub conflict_overrides: Option<Value>,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
28pub struct AreaPatch {
29 #[serde(rename = "tt", skip_serializing_if = "Option::is_none")]
31 pub title: Option<String>,
32
33 #[serde(rename = "tg", skip_serializing_if = "Option::is_none")]
35 pub tag_ids: Option<Vec<ThingsId>>,
36
37 #[serde(rename = "md", skip_serializing_if = "Option::is_none")]
39 pub modification_date: Option<f64>,
40
41 #[serde(rename = "ix", skip_serializing_if = "Option::is_none")]
43 pub sort_index: Option<i32>,
44}
45
46impl AreaPatch {
47 pub fn is_empty(&self) -> bool {
48 self.title.is_none()
49 && self.tag_ids.is_none()
50 && self.modification_date.is_none()
51 && self.sort_index.is_none()
52 }
53
54 pub fn into_properties(self) -> BTreeMap<String, Value> {
55 match serde_json::to_value(self) {
56 Ok(Value::Object(map)) => map.into_iter().collect(),
57 _ => BTreeMap::new(),
58 }
59 }
60}