chie_shared/types/
enums.rs

1//! Enum types for CHIE Protocol.
2
3#[cfg(feature = "schema")]
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8/// Content category for marketplace.
9///
10/// # Examples
11///
12/// ```
13/// use chie_shared::ContentCategory;
14///
15/// // Using specific categories for content classification
16/// let model_category = ContentCategory::ThreeDModels;
17/// let audio_category = ContentCategory::Audio;
18///
19/// // Display formatting for UI
20/// assert_eq!(model_category.to_string(), "3D Models");
21/// assert_eq!(audio_category.to_string(), "Audio");
22///
23/// // Default category
24/// let default = ContentCategory::default();
25/// assert_eq!(default, ContentCategory::Other);
26///
27/// // Serialization example
28/// let json = serde_json::to_string(&model_category).unwrap();
29/// assert_eq!(json, "\"THREE_D_MODELS\"");
30/// ```
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
32#[cfg_attr(feature = "schema", derive(JsonSchema))]
33#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
34pub enum ContentCategory {
35    /// 3D models (.fbx, .obj, .blend)
36    ThreeDModels,
37    /// Textures and materials
38    Textures,
39    /// Audio files (music, SFX)
40    Audio,
41    /// Scripts and code
42    Scripts,
43    /// Animations
44    Animations,
45    /// Complete asset packs
46    AssetPacks,
47    /// AI/ML models
48    AiModels,
49    /// Other content types
50    #[default]
51    Other,
52}
53
54impl fmt::Display for ContentCategory {
55    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56        match self {
57            Self::ThreeDModels => write!(f, "3D Models"),
58            Self::Textures => write!(f, "Textures"),
59            Self::Audio => write!(f, "Audio"),
60            Self::Scripts => write!(f, "Scripts"),
61            Self::Animations => write!(f, "Animations"),
62            Self::AssetPacks => write!(f, "Asset Packs"),
63            Self::AiModels => write!(f, "AI Models"),
64            Self::Other => write!(f, "Other"),
65        }
66    }
67}
68
69/// Content status in the system.
70///
71/// # Examples
72///
73/// ```
74/// use chie_shared::ContentStatus;
75///
76/// // Track content through its lifecycle
77/// let mut status = ContentStatus::default();
78/// assert_eq!(status, ContentStatus::Processing);
79///
80/// // After processing completes
81/// status = ContentStatus::Active;
82/// assert_eq!(status.to_string(), "Active");
83///
84/// // Check if content is available
85/// let is_available = matches!(status, ContentStatus::Active);
86/// assert!(is_available);
87///
88/// // Serialization for API responses
89/// let json = serde_json::to_string(&status).unwrap();
90/// assert_eq!(json, "\"ACTIVE\"");
91/// ```
92#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
93#[cfg_attr(feature = "schema", derive(JsonSchema))]
94#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
95pub enum ContentStatus {
96    /// Content is being processed (encrypted, pinned)
97    #[default]
98    Processing,
99    /// Content is active and available
100    Active,
101    /// Content is pending review
102    PendingReview,
103    /// Content was rejected
104    Rejected,
105    /// Content was removed
106    Removed,
107}
108
109impl fmt::Display for ContentStatus {
110    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111        match self {
112            Self::Processing => write!(f, "Processing"),
113            Self::Active => write!(f, "Active"),
114            Self::PendingReview => write!(f, "Pending Review"),
115            Self::Rejected => write!(f, "Rejected"),
116            Self::Removed => write!(f, "Removed"),
117        }
118    }
119}
120
121/// Node status.
122///
123/// # Examples
124///
125/// ```
126/// use chie_shared::NodeStatus;
127///
128/// // Check node availability
129/// let status = NodeStatus::Online;
130/// assert_eq!(status.to_string(), "Online");
131///
132/// // Filter operational nodes
133/// let nodes = vec![
134///     NodeStatus::Online,
135///     NodeStatus::Offline,
136///     NodeStatus::Syncing,
137///     NodeStatus::Banned,
138/// ];
139/// let operational: Vec<_> = nodes
140///     .iter()
141///     .filter(|s| matches!(s, NodeStatus::Online | NodeStatus::Syncing))
142///     .collect();
143/// assert_eq!(operational.len(), 2);
144///
145/// // Serialization
146/// let json = serde_json::to_string(&status).unwrap();
147/// assert_eq!(json, "\"ONLINE\"");
148/// ```
149#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
150#[cfg_attr(feature = "schema", derive(JsonSchema))]
151#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
152pub enum NodeStatus {
153    Online,
154    Offline,
155    Syncing,
156    Banned,
157}
158
159impl fmt::Display for NodeStatus {
160    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
161        match self {
162            Self::Online => write!(f, "Online"),
163            Self::Offline => write!(f, "Offline"),
164            Self::Syncing => write!(f, "Syncing"),
165            Self::Banned => write!(f, "Banned"),
166        }
167    }
168}
169
170/// User role in the system.
171///
172/// # Examples
173///
174/// ```
175/// use chie_shared::UserRole;
176///
177/// // Role-based access control
178/// let user_role = UserRole::Creator;
179/// assert_eq!(user_role.to_string(), "Creator");
180///
181/// // Permission checking
182/// let can_upload = matches!(user_role, UserRole::Creator | UserRole::Admin);
183/// assert!(can_upload);
184///
185/// // Admin privileges
186/// let admin_role = UserRole::Admin;
187/// let is_admin = admin_role == UserRole::Admin;
188/// assert!(is_admin);
189///
190/// // Serialization for JWT claims
191/// let json = serde_json::to_string(&user_role).unwrap();
192/// assert_eq!(json, "\"CREATOR\"");
193/// ```
194#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
195#[cfg_attr(feature = "schema", derive(JsonSchema))]
196#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
197pub enum UserRole {
198    /// Regular user (buyer/node operator)
199    User,
200    /// Content creator
201    Creator,
202    /// Platform administrator
203    Admin,
204}
205
206impl fmt::Display for UserRole {
207    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
208        match self {
209            Self::User => write!(f, "User"),
210            Self::Creator => write!(f, "Creator"),
211            Self::Admin => write!(f, "Admin"),
212        }
213    }
214}
215
216/// Demand level for content.
217///
218/// # Examples
219///
220/// ```
221/// use chie_shared::DemandLevel;
222///
223/// // Classify content demand for reward multipliers
224/// let demand = DemandLevel::High;
225/// assert_eq!(demand.to_string(), "High");
226///
227/// // Determine reward multiplier based on demand
228/// let multiplier = match demand {
229///     DemandLevel::Low => 1.0,
230///     DemandLevel::Medium => 1.5,
231///     DemandLevel::High => 2.0,
232///     DemandLevel::VeryHigh => 3.0,
233/// };
234/// assert_eq!(multiplier, 2.0);
235///
236/// // Serialization for analytics
237/// let json = serde_json::to_string(&demand).unwrap();
238/// assert_eq!(json, "\"HIGH\"");
239/// ```
240#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
241#[cfg_attr(feature = "schema", derive(JsonSchema))]
242#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
243pub enum DemandLevel {
244    Low,
245    Medium,
246    High,
247    VeryHigh,
248}
249
250impl fmt::Display for DemandLevel {
251    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
252        match self {
253            Self::Low => write!(f, "Low"),
254            Self::Medium => write!(f, "Medium"),
255            Self::High => write!(f, "High"),
256            Self::VeryHigh => write!(f, "Very High"),
257        }
258    }
259}
260
261/// Service status.
262///
263/// # Examples
264///
265/// ```
266/// use chie_shared::ServiceStatus;
267///
268/// // Health check monitoring
269/// let status = ServiceStatus::Healthy;
270/// assert_eq!(status.to_string(), "Healthy");
271///
272/// // Determine if service can handle requests
273/// let can_serve = !matches!(status, ServiceStatus::Down);
274/// assert!(can_serve);
275///
276/// // Alert on degradation
277/// let degraded_status = ServiceStatus::Degraded;
278/// let should_alert = matches!(degraded_status, ServiceStatus::Degraded | ServiceStatus::Down);
279/// assert!(should_alert);
280///
281/// // Serialization for status endpoint
282/// let json = serde_json::to_string(&status).unwrap();
283/// assert_eq!(json, "\"HEALTHY\"");
284/// ```
285#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
286#[cfg_attr(feature = "schema", derive(JsonSchema))]
287#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
288pub enum ServiceStatus {
289    /// Service is healthy.
290    Healthy,
291    /// Service is degraded.
292    Degraded,
293    /// Service is down.
294    Down,
295}
296
297impl fmt::Display for ServiceStatus {
298    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
299        match self {
300            Self::Healthy => write!(f, "Healthy"),
301            Self::Degraded => write!(f, "Degraded"),
302            Self::Down => write!(f, "Down"),
303        }
304    }
305}
306
307#[cfg(test)]
308mod tests {
309    use super::*;
310
311    #[test]
312    fn test_content_category_display() {
313        assert_eq!(ContentCategory::ThreeDModels.to_string(), "3D Models");
314        assert_eq!(ContentCategory::AiModels.to_string(), "AI Models");
315    }
316
317    #[test]
318    fn test_content_status_display() {
319        assert_eq!(ContentStatus::Processing.to_string(), "Processing");
320        assert_eq!(ContentStatus::PendingReview.to_string(), "Pending Review");
321    }
322
323    #[test]
324    fn test_node_status_display() {
325        assert_eq!(NodeStatus::Online.to_string(), "Online");
326        assert_eq!(NodeStatus::Offline.to_string(), "Offline");
327    }
328
329    #[test]
330    fn test_user_role_display() {
331        assert_eq!(UserRole::User.to_string(), "User");
332        assert_eq!(UserRole::Creator.to_string(), "Creator");
333        assert_eq!(UserRole::Admin.to_string(), "Admin");
334    }
335
336    #[test]
337    fn test_demand_level_display() {
338        assert_eq!(DemandLevel::Low.to_string(), "Low");
339        assert_eq!(DemandLevel::VeryHigh.to_string(), "Very High");
340    }
341
342    #[test]
343    fn test_service_status_display() {
344        assert_eq!(ServiceStatus::Healthy.to_string(), "Healthy");
345        assert_eq!(ServiceStatus::Degraded.to_string(), "Degraded");
346        assert_eq!(ServiceStatus::Down.to_string(), "Down");
347    }
348}