Skip to main content

ralph/undo/
model.rs

1//! Purpose: Define undo snapshot data models and restore result types.
2//!
3//! Responsibilities:
4//! - Define snapshot metadata and full snapshot payload types.
5//! - Define list/restore result wrappers used by CLI and core flows.
6//!
7//! Scope:
8//! - Data modeling only; file IO, restore, and pruning live in sibling modules.
9//!
10//! Usage:
11//! - Used through `crate::undo` by CLI and core flows.
12//!
13//! Invariants/Assumptions:
14//! - Snapshot payloads serialize both queue and done files together.
15//! - Snapshot IDs are timestamp-derived strings produced by storage helpers.
16
17use crate::contracts::QueueFile;
18use serde::{Deserialize, Serialize};
19
20/// Metadata about a single undo snapshot.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct UndoSnapshotMeta {
23    /// Unique snapshot ID (timestamp-based).
24    pub id: String,
25    /// Human-readable operation description.
26    pub operation: String,
27    /// RFC3339 timestamp when snapshot was created.
28    pub timestamp: String,
29}
30
31/// Full snapshot content (stored in JSON file).
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct UndoSnapshot {
34    /// Schema version for future migrations.
35    pub version: u32,
36    /// Human-readable operation description.
37    pub operation: String,
38    /// RFC3339 timestamp when snapshot was created.
39    pub timestamp: String,
40    /// Full queue.json content at snapshot time.
41    pub queue_json: QueueFile,
42    /// Full done.json content at snapshot time.
43    pub done_json: QueueFile,
44}
45
46/// Result of listing snapshots.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct SnapshotList {
49    pub snapshots: Vec<UndoSnapshotMeta>,
50}
51
52/// Result of a restore operation.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct RestoreResult {
55    pub snapshot_id: String,
56    pub operation: String,
57    pub timestamp: String,
58    pub tasks_affected: usize,
59}