1use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::SchemaType;
7
8#[cfg(feature = "typescript")]
9use ts_rs::TS;
10#[cfg(feature = "openapi")]
11use utoipa::ToSchema;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
15#[cfg_attr(feature = "typescript", derive(TS))]
16#[cfg_attr(feature = "typescript", ts(export))]
17#[cfg_attr(feature = "openapi", derive(ToSchema))]
18pub struct DataToSink {
19 pub payload: DataToSinkEvent,
20 pub public_key: String,
21 pub event_request_timestamp: u64,
22 pub event_ledger_timestamp: u64,
23 pub sink_timestamp: u64,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[cfg_attr(feature = "typescript", derive(TS))]
29#[cfg_attr(feature = "typescript", ts(export))]
30#[cfg_attr(feature = "openapi", derive(ToSchema))]
31#[serde(tag = "event", content = "data", rename_all = "snake_case")]
32pub enum DataToSinkEvent {
33 Create {
34 governance_id: Option<String>,
35 subject_id: String,
36 owner: String,
37 schema_id: SchemaType,
38 namespace: String,
39 sn: u64,
40 gov_version: u64,
41 state: Value,
42 },
43 FactFull {
44 governance_id: Option<String>,
45 subject_id: String,
46 schema_id: SchemaType,
47 viewpoints: Vec<String>,
48 issuer: String,
49 owner: String,
50 payload: Option<Value>,
51 patch: Option<Value>,
52 success: bool,
53 error: Option<String>,
54 sn: u64,
55 gov_version: u64,
56 },
57 FactOpaque {
58 governance_id: Option<String>,
59 subject_id: String,
60 schema_id: SchemaType,
61 viewpoints: Vec<String>,
62 owner: String,
63 success: bool,
64 sn: u64,
65 gov_version: u64,
66 },
67 Transfer {
68 governance_id: Option<String>,
69 subject_id: String,
70 schema_id: SchemaType,
71 owner: String,
72 new_owner: String,
73 success: bool,
74 error: Option<String>,
75 sn: u64,
76 gov_version: u64,
77 },
78 Confirm {
79 governance_id: Option<String>,
80 subject_id: String,
81 schema_id: SchemaType,
82 sn: u64,
83 patch: Option<Value>,
84 success: bool,
85 error: Option<String>,
86 gov_version: u64,
87 name_old_owner: Option<String>,
88 },
89 Reject {
90 governance_id: Option<String>,
91 subject_id: String,
92 schema_id: SchemaType,
93 sn: u64,
94 gov_version: u64,
95 },
96 Eol {
97 governance_id: Option<String>,
98 subject_id: String,
99 schema_id: SchemaType,
100 sn: u64,
101 gov_version: u64,
102 },
103}
104
105impl DataToSinkEvent {
106 pub fn get_subject_schema(&self) -> (String, String) {
108 match self {
109 Self::Create {
110 subject_id,
111 schema_id,
112 ..
113 }
114 | Self::FactFull {
115 subject_id,
116 schema_id,
117 ..
118 }
119 | Self::FactOpaque {
120 subject_id,
121 schema_id,
122 ..
123 }
124 | Self::Transfer {
125 subject_id,
126 schema_id,
127 ..
128 }
129 | Self::Confirm {
130 subject_id,
131 schema_id,
132 ..
133 }
134 | Self::Reject {
135 subject_id,
136 schema_id,
137 ..
138 }
139 | Self::Eol {
140 subject_id,
141 schema_id,
142 ..
143 } => (subject_id.clone(), schema_id.to_string()),
144 }
145 }
146}