1use crate::{Record, Value};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum MutationKind {
5 Insert,
6 Update,
7 Delete,
8 Recover,
9}
10
11#[derive(Debug, Clone, PartialEq)]
12pub struct InsertCommand {
13 pub entity: String,
14 pub values: Record,
15 pub trace_chain: Vec<crate::TraceNode>,
16}
17
18impl InsertCommand {
19 pub fn new(entity: impl Into<String>) -> Self {
20 Self {
21 entity: entity.into(),
22 values: Record::new(),
23 trace_chain: Vec::new(),
24 }
25 }
26
27 pub fn value(mut self, field: impl Into<String>, value: impl Into<Value>) -> Self {
28 self.values.insert(field.into(), value.into());
29 self
30 }
31}
32
33#[derive(Debug, Clone, PartialEq)]
34pub struct UpdateCommand {
35 pub entity: String,
36 pub id: Value,
37 pub expected_version: Option<i64>,
38 pub values: Record,
39 pub trace_chain: Vec<crate::TraceNode>,
40}
41
42impl UpdateCommand {
43 pub fn new(entity: impl Into<String>, id: impl Into<Value>) -> Self {
44 Self {
45 entity: entity.into(),
46 id: id.into(),
47 expected_version: None,
48 values: Record::new(),
49 trace_chain: Vec::new(),
50 }
51 }
52
53 pub fn expected_version(mut self, version: i64) -> Self {
54 self.expected_version = Some(version);
55 self
56 }
57
58 pub fn value(mut self, field: impl Into<String>, value: impl Into<Value>) -> Self {
59 self.values.insert(field.into(), value.into());
60 self
61 }
62}
63
64#[derive(Debug, Clone, PartialEq)]
65pub struct DeleteCommand {
66 pub entity: String,
67 pub id: Value,
68 pub expected_version: Option<i64>,
69 pub soft_delete: bool,
70 pub trace_chain: Vec<crate::TraceNode>,
71}
72
73impl DeleteCommand {
74 pub fn new(entity: impl Into<String>, id: impl Into<Value>) -> Self {
75 Self {
76 entity: entity.into(),
77 id: id.into(),
78 expected_version: None,
79 soft_delete: true,
80 trace_chain: Vec::new(),
81 }
82 }
83
84 pub fn expected_version(mut self, version: i64) -> Self {
85 self.expected_version = Some(version);
86 self
87 }
88
89 pub fn hard_delete(mut self) -> Self {
90 self.soft_delete = false;
91 self
92 }
93}
94
95#[derive(Debug, Clone, PartialEq)]
96pub struct RecoverCommand {
97 pub entity: String,
98 pub id: Value,
99 pub expected_version: i64,
100 pub trace_chain: Vec<crate::TraceNode>,
101}
102
103impl RecoverCommand {
104 pub fn new(entity: impl Into<String>, id: impl Into<Value>, expected_version: i64) -> Self {
105 Self {
106 entity: entity.into(),
107 id: id.into(),
108 expected_version,
109 trace_chain: Vec::new(),
110 }
111 }
112}