Skip to main content

systemprompt_sync/
result.rs

1//! Per-operation result types reported by [`crate::SyncService`].
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
6#[serde(tag = "kind", rename_all = "snake_case")]
7pub enum SyncOpState {
8    NotStarted,
9    Partial {
10        completed: usize,
11        total: usize,
12    },
13    #[default]
14    Completed,
15    Failed,
16}
17
18#[derive(Clone, Debug, Serialize, Deserialize)]
19pub struct SyncOperationResult {
20    pub operation: String,
21    pub success: bool,
22    pub items_synced: usize,
23    pub items_skipped: usize,
24    pub errors: Vec<String>,
25    pub details: Option<serde_json::Value>,
26    #[serde(default)]
27    pub state: SyncOpState,
28}
29
30impl SyncOperationResult {
31    pub fn success(operation: &str, items_synced: usize) -> Self {
32        Self {
33            operation: operation.to_string(),
34            success: true,
35            items_synced,
36            items_skipped: 0,
37            errors: vec![],
38            details: None,
39            state: SyncOpState::Completed,
40        }
41    }
42
43    pub fn with_details(mut self, details: serde_json::Value) -> Self {
44        self.details = Some(details);
45        self
46    }
47
48    pub fn dry_run(operation: &str, items_skipped: usize, details: serde_json::Value) -> Self {
49        Self {
50            operation: operation.to_string(),
51            success: true,
52            items_synced: 0,
53            items_skipped,
54            errors: vec![],
55            details: Some(details),
56            state: SyncOpState::Completed,
57        }
58    }
59}