wf-market 0.3.2

A Rust client library for the warframe.market API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
//! Common types shared across the API.
//!
//! This module contains fundamental types like Platform, Language,
//! and other shared enumerations used throughout the library.

use serde::{Deserialize, Serialize};

/// Gaming platform for warframe.market.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Platform {
    /// PC platform (default)
    #[default]
    Pc,
    /// PlayStation 4
    Ps4,
    /// Xbox
    Xbox,
    /// Nintendo Switch
    Switch,
    /// Mobile
    Mobile,
}

impl Platform {
    /// Get the API header value for this platform.
    pub fn as_header_value(&self) -> &'static str {
        match self {
            Platform::Pc => "pc",
            Platform::Ps4 => "ps4",
            Platform::Xbox => "xbox",
            Platform::Switch => "switch",
            Platform::Mobile => "mobile",
        }
    }

    /// Get all available platforms.
    pub fn all() -> &'static [Platform] {
        &[
            Platform::Pc,
            Platform::Ps4,
            Platform::Xbox,
            Platform::Switch,
            Platform::Mobile,
        ]
    }
}

impl std::fmt::Display for Platform {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Platform::Pc => write!(f, "PC"),
            Platform::Ps4 => write!(f, "PlayStation 4"),
            Platform::Xbox => write!(f, "Xbox"),
            Platform::Switch => write!(f, "Nintendo Switch"),
            Platform::Mobile => write!(f, "Mobile"),
        }
    }
}

/// Language for API responses.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Language {
    /// English (default)
    #[default]
    #[serde(rename = "en")]
    English,
    /// Korean
    #[serde(rename = "ko")]
    Korean,
    /// Russian
    #[serde(rename = "ru")]
    Russian,
    /// German
    #[serde(rename = "de")]
    German,
    /// French
    #[serde(rename = "fr")]
    French,
    /// Portuguese
    #[serde(rename = "pt")]
    Portuguese,
    /// Simplified Chinese
    #[serde(rename = "zh-hans")]
    ChineseSimplified,
    /// Traditional Chinese
    #[serde(rename = "zh-hant")]
    ChineseTraditional,
    /// Spanish
    #[serde(rename = "es")]
    Spanish,
    /// Italian
    #[serde(rename = "it")]
    Italian,
    /// Polish
    #[serde(rename = "pl")]
    Polish,
    /// Ukrainian
    #[serde(rename = "uk")]
    Ukrainian,
}

impl Language {
    /// Get the API header/parameter value for this language.
    pub fn as_code(&self) -> &'static str {
        match self {
            Language::English => "en",
            Language::Korean => "ko",
            Language::Russian => "ru",
            Language::German => "de",
            Language::French => "fr",
            Language::Portuguese => "pt",
            Language::ChineseSimplified => "zh-hans",
            Language::ChineseTraditional => "zh-hant",
            Language::Spanish => "es",
            Language::Italian => "it",
            Language::Polish => "pl",
            Language::Ukrainian => "uk",
        }
    }

    /// Get all available languages.
    pub fn all() -> &'static [Language] {
        &[
            Language::English,
            Language::Korean,
            Language::Russian,
            Language::German,
            Language::French,
            Language::Portuguese,
            Language::ChineseSimplified,
            Language::ChineseTraditional,
            Language::Spanish,
            Language::Italian,
            Language::Polish,
            Language::Ukrainian,
        ]
    }
}

impl std::fmt::Display for Language {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Language::English => write!(f, "English"),
            Language::Korean => write!(f, "Korean"),
            Language::Russian => write!(f, "Russian"),
            Language::German => write!(f, "German"),
            Language::French => write!(f, "French"),
            Language::Portuguese => write!(f, "Portuguese"),
            Language::ChineseSimplified => write!(f, "Chinese (Simplified)"),
            Language::ChineseTraditional => write!(f, "Chinese (Traditional)"),
            Language::Spanish => write!(f, "Spanish"),
            Language::Italian => write!(f, "Italian"),
            Language::Polish => write!(f, "Polish"),
            Language::Ukrainian => write!(f, "Ukrainian"),
        }
    }
}

/// User online status.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum UserStatus {
    /// User is offline
    #[default]
    Offline,
    /// User is online
    Online,
    /// User is in-game
    Ingame,
    /// User is invisible (appears offline to others)
    Invisible,
}

impl UserStatus {
    /// Check if the user is available for trading.
    pub fn is_available(&self) -> bool {
        matches!(self, UserStatus::Online | UserStatus::Ingame)
    }
}

impl std::fmt::Display for UserStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            UserStatus::Offline => write!(f, "Offline"),
            UserStatus::Online => write!(f, "Online"),
            UserStatus::Ingame => write!(f, "In Game"),
            UserStatus::Invisible => write!(f, "Invisible"),
        }
    }
}

/// Order type (buy or sell).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum OrderType {
    /// Buying order (WTB - Want To Buy)
    Buy,
    /// Selling order (WTS - Want To Sell)
    Sell,
}

impl std::fmt::Display for OrderType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            OrderType::Buy => write!(f, "Buy"),
            OrderType::Sell => write!(f, "Sell"),
        }
    }
}

/// Item rarity.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Rarity {
    Common,
    Uncommon,
    Rare,
    Legendary,
}

impl std::fmt::Display for Rarity {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Rarity::Common => write!(f, "Common"),
            Rarity::Uncommon => write!(f, "Uncommon"),
            Rarity::Rare => write!(f, "Rare"),
            Rarity::Legendary => write!(f, "Legendary"),
        }
    }
}

/// Riven weapon type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum RivenType {
    Kitgun,
    Melee,
    Pistol,
    Rifle,
    Shotgun,
    Zaw,
}

impl std::fmt::Display for RivenType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            RivenType::Kitgun => write!(f, "Kitgun"),
            RivenType::Melee => write!(f, "Melee"),
            RivenType::Pistol => write!(f, "Pistol"),
            RivenType::Rifle => write!(f, "Rifle"),
            RivenType::Shotgun => write!(f, "Shotgun"),
            RivenType::Zaw => write!(f, "Zaw"),
        }
    }
}

/// User in-game activity type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ActivityType {
    #[default]
    Unknown,
    Idle,
    OnMission,
    InDojo,
    InOrbiter,
    InRelay,
}

impl std::fmt::Display for ActivityType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ActivityType::Unknown => write!(f, "Unknown"),
            ActivityType::Idle => write!(f, "Idle"),
            ActivityType::OnMission => write!(f, "On Mission"),
            ActivityType::InDojo => write!(f, "In Dojo"),
            ActivityType::InOrbiter => write!(f, "In Orbiter"),
            ActivityType::InRelay => write!(f, "In Relay"),
        }
    }
}

/// User in-game activity.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Activity {
    /// Type of activity
    #[serde(rename = "type")]
    pub activity_type: ActivityType,

    /// Activity details (e.g., mission name, max 64 chars)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub details: Option<String>,

    /// When the activity started
    #[serde(rename = "startedAt", skip_serializing_if = "Option::is_none")]
    pub started_at: Option<chrono::DateTime<chrono::Utc>>,
}

impl Activity {
    /// Create a new activity.
    pub fn new(activity_type: ActivityType) -> Self {
        Self {
            activity_type,
            details: None,
            started_at: None,
        }
    }

    /// Set activity details.
    pub fn with_details(mut self, details: impl Into<String>) -> Self {
        self.details = Some(details.into());
        self
    }

    /// Set activity start time.
    pub fn with_started_at(mut self, started_at: chrono::DateTime<chrono::Utc>) -> Self {
        self.started_at = Some(started_at);
        self
    }
}

/// UI theme preference.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Theme {
    /// Light theme
    Light,
    /// Dark theme
    Dark,
    /// Follow system preference
    #[default]
    System,
}

impl std::fmt::Display for Theme {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Theme::Light => write!(f, "Light"),
            Theme::Dark => write!(f, "Dark"),
            Theme::System => write!(f, "System"),
        }
    }
}

/// User role on the site.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum UserRole {
    /// Regular user
    #[default]
    User,
    /// Moderator
    Moderator,
    /// Administrator
    Admin,
}

impl std::fmt::Display for UserRole {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            UserRole::User => write!(f, "User"),
            UserRole::Moderator => write!(f, "Moderator"),
            UserRole::Admin => write!(f, "Admin"),
        }
    }
}

/// Subscription tier.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SubscriptionTier {
    /// No subscription
    #[default]
    None,
    /// Bronze tier
    Bronze,
    /// Silver tier
    Silver,
    /// Gold tier
    Gold,
    /// Diamond tier
    Diamond,
}

impl std::fmt::Display for SubscriptionTier {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            SubscriptionTier::None => write!(f, "None"),
            SubscriptionTier::Bronze => write!(f, "Bronze"),
            SubscriptionTier::Silver => write!(f, "Silver"),
            SubscriptionTier::Gold => write!(f, "Gold"),
            SubscriptionTier::Diamond => write!(f, "Diamond"),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_platform_serialization() {
        assert_eq!(serde_json::to_string(&Platform::Pc).unwrap(), "\"pc\"");
        assert_eq!(serde_json::to_string(&Platform::Ps4).unwrap(), "\"ps4\"");
    }

    #[test]
    fn test_language_codes() {
        assert_eq!(Language::English.as_code(), "en");
        assert_eq!(Language::ChineseSimplified.as_code(), "zh-hans");
    }

    #[test]
    fn test_user_status_availability() {
        assert!(UserStatus::Online.is_available());
        assert!(UserStatus::Ingame.is_available());
        assert!(!UserStatus::Offline.is_available());
        assert!(!UserStatus::Invisible.is_available());
    }
}