sure_client_rs/models/
sync.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7#[serde(rename_all = "lowercase")]
8pub enum SyncStatus {
9 Pending,
11 Syncing,
13 Completed,
15 Failed,
17}
18
19impl std::fmt::Display for SyncStatus {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 match self {
22 Self::Pending => write!(f, "pending"),
23 Self::Syncing => write!(f, "syncing"),
24 Self::Completed => write!(f, "completed"),
25 Self::Failed => write!(f, "failed"),
26 }
27 }
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct ParseSyncStatusError(String);
33
34impl std::fmt::Display for ParseSyncStatusError {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 write!(f, "Invalid sync status: {}", self.0)
37 }
38}
39
40impl std::error::Error for ParseSyncStatusError {}
41
42impl std::str::FromStr for SyncStatus {
43 type Err = ParseSyncStatusError;
44
45 fn from_str(s: &str) -> Result<Self, Self::Err> {
46 match s {
47 "pending" => Ok(Self::Pending),
48 "syncing" => Ok(Self::Syncing),
49 "completed" => Ok(Self::Completed),
50 "failed" => Ok(Self::Failed),
51 _ => Err(ParseSyncStatusError(s.to_string())),
52 }
53 }
54}
55
56impl TryFrom<&str> for SyncStatus {
57 type Error = ParseSyncStatusError;
58
59 fn try_from(value: &str) -> Result<Self, Self::Error> {
60 value.parse()
61 }
62}
63
64impl TryFrom<String> for SyncStatus {
65 type Error = ParseSyncStatusError;
66
67 fn try_from(value: String) -> Result<Self, Self::Error> {
68 value.parse()
69 }
70}
71
72#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
74#[cfg_attr(feature = "strict", serde(deny_unknown_fields))]
75pub struct SyncResponse {
76 pub id: Uuid,
78 pub status: SyncStatus,
80 pub syncable_type: String,
82 pub syncable_id: Uuid,
84 #[serde(default, skip_serializing_if = "Option::is_none")]
86 pub syncing_at: Option<DateTime<Utc>>,
87 #[serde(default, skip_serializing_if = "Option::is_none")]
89 pub completed_at: Option<DateTime<Utc>>,
90 #[serde(default, skip_serializing_if = "Option::is_none")]
92 pub window_start_date: Option<DateTime<Utc>>,
93 #[serde(default, skip_serializing_if = "Option::is_none")]
95 pub window_end_date: Option<DateTime<Utc>>,
96 pub message: String,
98}