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