Skip to main content

redis_cloud/
types.rs

1//! Common types for Redis Cloud API
2//!
3//! This module contains shared types used across multiple endpoints.
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8// ============================================================================
9// Task Types (Most common - appears in 37 endpoints)
10// ============================================================================
11
12/// `TaskStateUpdate` - Line 9725 in `OpenAPI` spec
13/// Represents the state of an asynchronous task
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct TaskStateUpdate {
17    /// UUID of the task
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub task_id: Option<String>,
20
21    /// Type of command being executed
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub command_type: Option<String>,
24
25    /// Current status of the task
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub status: Option<TaskStatus>,
28
29    /// Description of the task
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub description: Option<String>,
32
33    /// Timestamp of the task update
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub timestamp: Option<String>,
36
37    /// Response from the processor
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub response: Option<ProcessorResponse>,
40
41    /// HATEOAS links for related resources
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub links: Option<Vec<Link>>,
44}
45
46/// `TaskStatus` enum - Part of `TaskStateUpdate` schema
47#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
48#[serde(rename_all = "kebab-case")]
49pub enum TaskStatus {
50    Initialized,
51    Received,
52    ProcessingInProgress,
53    ProcessingCompleted,
54    ProcessingError,
55}
56
57/// `ProcessorResponse` - Line 14268 in `OpenAPI` spec
58/// Contains the result or error from task processing
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(rename_all = "camelCase")]
61pub struct ProcessorResponse {
62    /// ID of the primary resource created/modified
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub resource_id: Option<i32>,
65
66    /// ID of an additional resource if applicable
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub additional_resource_id: Option<i32>,
69
70    /// The resource object itself
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub resource: Option<std::collections::HashMap<String, Value>>,
73
74    /// Error message if the operation failed
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub error: Option<String>,
77
78    /// Additional information about the operation
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub additional_info: Option<String>,
81}
82
83/// `ProcessorError` - Subset of massive error enum for common errors
84/// Full enum has 600+ values, we'll add as needed
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub enum ProcessorError {
87    #[serde(rename = "UNAUTHORIZED")]
88    Unauthorized,
89    #[serde(rename = "NOT_FOUND")]
90    NotFound,
91    #[serde(rename = "BAD_REQUEST")]
92    BadRequest,
93    #[serde(rename = "GENERAL_ERROR")]
94    GeneralError,
95    #[serde(other)]
96    Other,
97}
98
99/// `TasksStateUpdate` - Collection of task updates
100#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct TasksStateUpdate {
102    pub tasks: Vec<TaskStateUpdate>,
103}
104
105// ============================================================================
106// Tag Types (Used in database and subscription endpoints)
107// ============================================================================
108
109/// `CloudTag` - Individual tag with key-value
110#[derive(Debug, Clone, Serialize, Deserialize)]
111pub struct CloudTag {
112    pub key: String,
113    pub value: String,
114}
115
116/// `CloudTags` - Collection of tags
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct CloudTags {
119    pub tags: Vec<CloudTag>,
120}
121
122// ============================================================================
123// Common Response Types
124// ============================================================================
125
126/// Generic paginated response wrapper
127#[derive(Debug, Clone, Serialize, Deserialize)]
128pub struct PaginatedResponse<T> {
129    /// The actual data items
130    #[serde(flatten)]
131    pub data: T,
132
133    /// Pagination metadata
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub offset: Option<u32>,
136
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub limit: Option<u32>,
139
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub total: Option<u32>,
142}
143
144/// HATEOAS Link object for API navigation
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct Link {
147    pub rel: String,
148    pub href: String,
149
150    #[serde(skip_serializing_if = "Option::is_none")]
151    pub method: Option<String>,
152
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub r#type: Option<String>,
155}
156
157/// Links collection
158#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct Links {
160    pub links: Vec<Link>,
161}
162
163// ============================================================================
164// Common Enums used across multiple endpoints
165// ============================================================================
166
167/// Cloud provider enum
168#[derive(Debug, Clone, Serialize, Deserialize)]
169#[serde(rename_all = "UPPERCASE")]
170pub enum CloudProvider {
171    Aws,
172    Gcp,
173    Azure,
174}
175
176/// Database protocol
177#[derive(Debug, Clone, Serialize, Deserialize)]
178#[serde(rename_all = "lowercase")]
179pub enum Protocol {
180    Redis,
181    Memcached,
182    Stack,
183}
184
185/// Data persistence options
186#[derive(Debug, Clone, Serialize, Deserialize)]
187pub enum DataPersistence {
188    #[serde(rename = "none")]
189    None,
190    #[serde(rename = "aof-every-1-sec")]
191    AofEvery1Sec,
192    #[serde(rename = "aof-every-write")]
193    AofEveryWrite,
194    #[serde(rename = "snapshot-every-1-hour")]
195    SnapshotEvery1Hour,
196    #[serde(rename = "snapshot-every-6-hours")]
197    SnapshotEvery6Hours,
198    #[serde(rename = "snapshot-every-12-hours")]
199    SnapshotEvery12Hours,
200}
201
202/// Subscription status
203#[derive(Debug, Clone, Serialize, Deserialize)]
204#[serde(rename_all = "lowercase")]
205pub enum SubscriptionStatus {
206    Pending,
207    Active,
208    Deleting,
209    Error,
210}
211
212/// Database status
213#[derive(Debug, Clone, Serialize, Deserialize)]
214#[serde(rename_all = "lowercase")]
215pub enum DatabaseStatus {
216    Pending,
217    Active,
218    ActiveChangePending,
219    ImportPending,
220    DeletePending,
221    Recovery,
222    Error,
223}
224
225// ============================================================================
226// Utility Types
227// ============================================================================
228
229/// Empty response for successful operations with no body
230#[derive(Debug, Clone, Serialize, Deserialize)]
231pub struct EmptyResponse {}
232
233/// Generic error response structure
234/// Note: The actual API may return different error formats,
235/// this is a common structure we'll adapt as needed
236#[derive(Debug, Clone, Serialize, Deserialize)]
237pub struct ErrorResponse {
238    #[serde(skip_serializing_if = "Option::is_none")]
239    pub error: Option<String>,
240
241    #[serde(skip_serializing_if = "Option::is_none")]
242    pub message: Option<String>,
243
244    #[serde(skip_serializing_if = "Option::is_none")]
245    pub description: Option<String>,
246
247    #[serde(skip_serializing_if = "Option::is_none")]
248    pub status_code: Option<u16>,
249}