systemprompt_sync/models/
local_sync.rs1use chrono::{DateTime, Utc};
6use serde::Serialize;
7use std::fmt;
8use systemprompt_identifiers::SourceId;
9
10#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
11pub enum LocalSyncDirection {
12 #[default]
13 ToDisk,
14 ToDatabase,
15}
16
17impl fmt::Display for LocalSyncDirection {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 match self {
20 Self::ToDisk => write!(f, "to_disk"),
21 Self::ToDatabase => write!(f, "to_database"),
22 }
23 }
24}
25
26#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
27pub enum DiffStatus {
28 Added,
29 Removed,
30 Modified,
31}
32
33#[derive(Clone, Debug, Serialize)]
34pub struct ContentDiffItem {
35 pub slug: String,
36 pub source_id: SourceId,
37 pub status: DiffStatus,
38 pub disk_hash: Option<String>,
39 pub db_hash: Option<String>,
40 pub disk_updated_at: Option<DateTime<Utc>>,
41 pub db_updated_at: Option<DateTime<Utc>>,
42 pub title: Option<String>,
43}
44
45#[derive(Clone, Debug, Serialize)]
46pub struct ContentDiffResult {
47 pub source_id: SourceId,
48 pub added: Vec<ContentDiffItem>,
49 pub removed: Vec<ContentDiffItem>,
50 pub modified: Vec<ContentDiffItem>,
51 pub unchanged: usize,
52}
53
54impl Default for ContentDiffResult {
55 fn default() -> Self {
56 Self {
57 source_id: SourceId::new(""),
58 added: Vec::new(),
59 removed: Vec::new(),
60 modified: Vec::new(),
61 unchanged: 0,
62 }
63 }
64}
65
66impl ContentDiffResult {
67 pub fn has_changes(&self) -> bool {
68 !self.added.is_empty() || !self.removed.is_empty() || !self.modified.is_empty()
69 }
70}
71
72#[derive(Clone, Debug, Default, Serialize)]
73pub struct LocalSyncResult {
74 pub items_synced: usize,
75 pub items_skipped: usize,
76 pub items_skipped_modified: usize,
77 pub items_deleted: usize,
78 pub errors: Vec<String>,
79 pub direction: LocalSyncDirection,
80}
81
82#[derive(Debug)]
83pub struct DiskContent {
84 pub slug: String,
85 pub title: String,
86 pub body: String,
87}