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