1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct User {
9 pub id: String,
11 pub email: String,
13 pub role: String,
15 pub created_at: String,
17 pub wallet_address: Option<String>,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct AuthResponse {
24 pub token: String,
26 pub user: User,
28 pub expires_at: Option<String>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct Database {
35 pub name: String,
37 pub tables: Vec<String>,
39 pub created_at: Option<String>,
41 pub size: Option<u64>,
43 pub record_count: Option<u64>,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct Table {
50 pub name: String,
52 pub columns: Vec<Column>,
54 pub row_count: Option<u64>,
56 pub size: Option<u64>,
58 pub created_at: Option<String>,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct Column {
65 pub name: String,
67 pub data_type: String,
69 pub nullable: bool,
71 pub default_value: Option<String>,
73 pub is_primary_key: bool,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct QueryResult {
80 pub data: QueryData,
82 pub meta: QueryMeta,
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct QueryData {
89 pub columns: Option<Vec<String>>,
91 pub rows: Vec<Vec<serde_json::Value>>,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct QueryMeta {
98 pub row_count: u64,
100 pub execution_time_ms: Option<u64>,
102 pub operation_type: OperationType,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108pub enum OperationType {
109 Read,
111 Write,
113 Schema,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct HealthStatus {
120 pub status: String,
122 pub version: String,
124 pub database: String,
126 pub blockchain: String,
128 pub uptime: Option<u64>,
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct SystemStats {
135 pub databases: u64,
137 pub tables: u64,
139 pub rows: u64,
141 pub storage_bytes: Option<u64>,
143 pub active_connections: Option<u64>,
145}
146
147#[cfg(feature = "migration")]
149#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct MigrationStatus {
151 pub id: String,
153 pub status: MigrationState,
155 pub records_processed: u64,
157 pub total_records: Option<u64>,
159 pub started_at: String,
161 pub completed_at: Option<String>,
163 pub error: Option<String>,
165}
166
167#[cfg(feature = "migration")]
169#[derive(Debug, Clone, Serialize, Deserialize)]
170pub enum MigrationState {
171 Pending,
173 Running,
175 Completed,
177 Failed,
179 Cancelled,
181}
182
183#[cfg(feature = "sync")]
185#[derive(Debug, Clone, Serialize, Deserialize)]
186pub struct SyncConfig {
187 pub name: String,
189 pub source_type: String,
191 pub source: String,
193 pub target: String,
195 pub interval: u64,
197 pub created_at: String,
199 pub last_sync: Option<String>,
201 pub status: SyncStatus,
203}
204
205#[cfg(feature = "sync")]
207#[derive(Debug, Clone, Serialize, Deserialize)]
208pub enum SyncStatus {
209 Stopped,
211 Running,
213 Error {
215 message: String,
217 },
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
222pub struct Pagination {
223 pub offset: u64,
225 pub limit: u64,
227}
228
229impl Default for Pagination {
230 fn default() -> Self {
231 Self {
232 offset: 0,
233 limit: 100,
234 }
235 }
236}
237
238#[derive(Debug, Clone, Default)]
240pub struct QueryOptions {
241 pub max_rows: Option<u64>,
243 pub timeout_ms: Option<u64>,
245 pub include_meta: bool,
247}
248
249#[derive(Debug, Clone, Serialize, Deserialize)]
251pub struct BatchResult {
252 pub successful: u64,
254 pub failed: u64,
256 pub errors: Vec<BatchError>,
258}
259
260#[derive(Debug, Clone, Serialize, Deserialize)]
262pub struct BatchError {
263 pub index: u64,
265 pub message: String,
267}
268
269#[derive(Debug, Clone, Serialize, Deserialize)]
271pub struct ApiResponse<T> {
272 pub data: T,
274 pub success: bool,
276 pub message: Option<String>,
278 pub meta: Option<HashMap<String, serde_json::Value>>,
280}
281
282#[derive(Debug, Clone)]
284pub struct RequestMeta {
285 pub request_id: Option<String>,
287 pub timestamp: chrono::DateTime<chrono::Utc>,
289 pub timeout: std::time::Duration,
291}
292
293impl Default for RequestMeta {
294 fn default() -> Self {
295 Self {
296 request_id: Some(uuid::Uuid::new_v4().to_string()),
297 timestamp: chrono::Utc::now(),
298 timeout: std::time::Duration::from_secs(30),
299 }
300 }
301}
302
303#[cfg(test)]
304mod tests {
305 use super::*;
306
307 #[test]
308 fn test_pagination_default() {
309 let pagination = Pagination::default();
310 assert_eq!(pagination.offset, 0);
311 assert_eq!(pagination.limit, 100);
312 }
313
314 #[test]
315 fn test_query_options_default() {
316 let options = QueryOptions::default();
317 assert!(options.max_rows.is_none());
318 assert!(options.timeout_ms.is_none());
319 assert!(!options.include_meta);
320 }
321
322 #[test]
323 fn test_user_serialization() {
324 let user = User {
325 id: "123".to_string(),
326 email: "test@example.com".to_string(),
327 role: "user".to_string(),
328 created_at: "2023-01-01T00:00:00Z".to_string(),
329 wallet_address: Some("0x1234567890abcdef".to_string()),
330 };
331
332 let json = serde_json::to_string(&user).unwrap();
333 let deserialized: User = serde_json::from_str(&json).unwrap();
334
335 assert_eq!(user.id, deserialized.id);
336 assert_eq!(user.email, deserialized.email);
337 assert_eq!(user.wallet_address, deserialized.wallet_address);
338 }
339}