Skip to main content

systemprompt_sync/
result.rs

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