Skip to main content

things3_cloud/wire/
checklist.rs

1use crate::ids::ThingsId;
2use crate::wire::task::TaskStatus;
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use std::collections::BTreeMap;
6
7/// Checklist item wire properties.
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
9pub struct ChecklistItemProps {
10    /// `tt`: checklist item title.
11    #[serde(rename = "tt", default)]
12    pub title: String,
13
14    /// `ss`: checklist item status.
15    #[serde(rename = "ss", default)]
16    pub status: TaskStatus,
17
18    /// `sp`: completion/cancellation timestamp.
19    #[serde(rename = "sp", default)]
20    pub stop_date: Option<f64>,
21
22    /// `ts`: parent task IDs (normally a single task UUID).
23    #[serde(rename = "ts", default)]
24    pub task_ids: Vec<ThingsId>,
25
26    /// `ix`: sort index within checklist.
27    #[serde(rename = "ix", default)]
28    pub sort_index: i32,
29
30    /// `cd`: creation timestamp.
31    #[serde(rename = "cd", default)]
32    pub creation_date: Option<f64>,
33
34    /// `md`: modification timestamp.
35    #[serde(rename = "md", default)]
36    pub modification_date: Option<f64>,
37
38    /// `lt`: leaves tombstone on delete.
39    #[serde(rename = "lt", default)]
40    pub leaves_tombstone: bool,
41
42    /// `xx`: conflict override metadata.
43    #[serde(rename = "xx", default)]
44    pub conflict_overrides: Option<Value>,
45}
46
47/// Sparse patch fields for ChecklistItem `t=1` updates.
48#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
49pub struct ChecklistItemPatch {
50    /// `tt`: title.
51    #[serde(rename = "tt", skip_serializing_if = "Option::is_none")]
52    pub title: Option<String>,
53
54    /// `ss`: status.
55    #[serde(rename = "ss", skip_serializing_if = "Option::is_none")]
56    pub status: Option<TaskStatus>,
57
58    /// `ts`: parent task IDs.
59    #[serde(rename = "ts", skip_serializing_if = "Option::is_none")]
60    pub task_ids: Option<Vec<ThingsId>>,
61
62    /// `ix`: sort index.
63    #[serde(rename = "ix", skip_serializing_if = "Option::is_none")]
64    pub sort_index: Option<i32>,
65
66    /// `cd`: creation timestamp.
67    #[serde(rename = "cd", skip_serializing_if = "Option::is_none")]
68    pub creation_date: Option<f64>,
69
70    /// `md`: modification timestamp.
71    #[serde(rename = "md", skip_serializing_if = "Option::is_none")]
72    pub modification_date: Option<f64>,
73}
74
75impl ChecklistItemPatch {
76    pub fn is_empty(&self) -> bool {
77        self.title.is_none()
78            && self.status.is_none()
79            && self.task_ids.is_none()
80            && self.sort_index.is_none()
81            && self.creation_date.is_none()
82            && self.modification_date.is_none()
83    }
84
85    pub fn into_properties(self) -> BTreeMap<String, Value> {
86        match serde_json::to_value(self) {
87            Ok(Value::Object(map)) => map.into_iter().collect(),
88            _ => BTreeMap::new(),
89        }
90    }
91}