wf-market 0.2.1

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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
//! User models for warframe.market.
//!
//! This module provides types for representing users, including
//! minimal user info (attached to orders) and full user profiles.

use chrono::{DateTime, Utc};
use serde::Deserialize;

use serde::Serialize;

use super::common::{Activity, Language, Platform, SubscriptionTier, Theme, UserRole, UserStatus};

/// Minimal user information (attached to orders and listings).
#[derive(Debug, Clone, Deserialize)]
pub struct User {
    /// Unique user identifier
    pub id: String,

    /// In-game name (IGN)
    #[serde(rename = "ingameName")]
    pub ingame_name: String,

    /// Path to user avatar (relative to static assets)
    #[serde(default)]
    pub avatar: Option<String>,

    /// User reputation score
    #[serde(default)]
    pub reputation: i32,

    /// Preferred locale
    #[serde(default)]
    pub locale: Option<String>,

    /// User's gaming platform
    pub platform: Platform,

    /// Whether cross-play is enabled
    #[serde(default)]
    pub crossplay: bool,

    /// Current online status
    #[serde(rename = "status", default)]
    pub status: UserStatus,

    /// Current in-game activity
    #[serde(default)]
    pub activity: Option<Activity>,

    /// Last seen timestamp
    #[serde(rename = "lastSeen", default)]
    pub last_seen: Option<DateTime<Utc>>,
}

impl User {
    /// Check if the user is currently available for trading.
    pub fn is_available(&self) -> bool {
        self.status.is_available()
    }

    /// Get the avatar URL (relative to static assets base).
    pub fn avatar_url(&self) -> Option<&str> {
        self.avatar.as_deref()
    }
}

/// Full user information (returned from /me endpoint).
#[derive(Debug, Clone, Deserialize)]
pub struct FullUser {
    /// Unique user identifier
    pub id: String,

    /// In-game name (IGN)
    #[serde(rename = "ingameName")]
    pub ingame_name: String,

    /// URL-friendly identifier
    #[serde(default)]
    pub slug: Option<String>,

    /// Path to user avatar
    #[serde(default)]
    pub avatar: Option<String>,

    /// Path to profile background
    #[serde(default)]
    pub background: Option<String>,

    /// Profile description (may contain HTML)
    #[serde(default)]
    pub about: Option<String>,

    /// User reputation score
    #[serde(default)]
    pub reputation: i32,

    /// In-game mastery rank
    #[serde(rename = "masteryLevel", default)]
    pub mastery_level: Option<u32>,

    /// User's gaming platform
    pub platform: Platform,

    /// Whether cross-play is enabled
    #[serde(default)]
    pub crossplay: bool,

    /// Preferred locale
    #[serde(default)]
    pub locale: Option<String>,

    /// Current online status
    #[serde(rename = "status", default)]
    pub status: UserStatus,

    /// Current in-game activity
    #[serde(default)]
    pub activity: Option<Activity>,

    /// Last seen timestamp
    #[serde(rename = "lastSeen", default)]
    pub last_seen: Option<DateTime<Utc>>,

    /// Whether the user is banned
    #[serde(default)]
    pub banned: Option<bool>,

    /// Ban expiration time
    #[serde(rename = "banUntil", default)]
    pub ban_until: Option<DateTime<Utc>>,

    /// Ban reason message
    #[serde(rename = "banMessage", default)]
    pub ban_message: Option<String>,

    /// Whether the user has an active warning
    #[serde(default)]
    pub warned: Option<bool>,

    /// Warning message
    #[serde(rename = "warnMessage", default)]
    pub warn_message: Option<String>,

    /// Email address (only visible to self)
    #[serde(default)]
    pub email: Option<String>,

    /// Whether email is verified
    #[serde(rename = "emailVerified", default)]
    pub email_verified: Option<bool>,

    /// Whether IGN is verified
    #[serde(rename = "ingameVerified", default)]
    pub ingame_verified: Option<bool>,
}

impl FullUser {
    /// Check if the user is currently available for trading.
    pub fn is_available(&self) -> bool {
        self.status.is_available()
    }

    /// Check if the user is banned.
    pub fn is_banned(&self) -> bool {
        self.banned.unwrap_or(false)
    }

    /// Check if the user has an active warning.
    pub fn has_warning(&self) -> bool {
        self.warned.unwrap_or(false)
    }

    /// Convert to minimal user info.
    pub fn to_user(&self) -> User {
        User {
            id: self.id.clone(),
            ingame_name: self.ingame_name.clone(),
            avatar: self.avatar.clone(),
            reputation: self.reputation,
            locale: self.locale.clone(),
            platform: self.platform,
            crossplay: self.crossplay,
            status: self.status,
            activity: self.activity.clone(),
            last_seen: self.last_seen,
        }
    }
}

/// Public user profile (from /user/{slug} endpoint).
#[derive(Debug, Clone, Deserialize)]
pub struct UserProfile {
    /// Unique user identifier
    pub id: String,

    /// In-game name (IGN)
    #[serde(rename = "ingameName")]
    pub ingame_name: String,

    /// URL-friendly identifier
    pub slug: String,

    /// Path to user avatar
    #[serde(default)]
    pub avatar: Option<String>,

    /// Path to profile background
    #[serde(default)]
    pub background: Option<String>,

    /// Profile description (may contain HTML)
    #[serde(default)]
    pub about: Option<String>,

    /// User reputation score
    #[serde(default)]
    pub reputation: i32,

    /// In-game mastery rank
    #[serde(rename = "masteryLevel", default)]
    pub mastery_level: Option<u32>,

    /// User's gaming platform
    pub platform: Platform,

    /// Whether cross-play is enabled
    #[serde(default)]
    pub crossplay: bool,

    /// Preferred locale
    #[serde(default)]
    pub locale: Option<String>,

    /// Current online status
    #[serde(rename = "status", default)]
    pub status: UserStatus,

    /// Current in-game activity
    #[serde(default)]
    pub activity: Option<Activity>,

    /// Last seen timestamp
    #[serde(rename = "lastSeen", default)]
    pub last_seen: Option<DateTime<Utc>>,

    /// Featured achievements on profile
    #[serde(rename = "achievementShowcase", default)]
    pub achievement_showcase: Vec<Achievement>,

    /// Whether the user is banned
    #[serde(default)]
    pub banned: Option<bool>,

    /// Ban expiration time
    #[serde(rename = "banUntil", default)]
    pub ban_until: Option<DateTime<Utc>>,

    /// Ban reason message
    #[serde(rename = "banMessage", default)]
    pub ban_message: Option<String>,

    /// Whether the user has an active warning
    #[serde(default)]
    pub warned: Option<bool>,

    /// Warning message
    #[serde(rename = "warnMessage", default)]
    pub warn_message: Option<String>,
}

impl UserProfile {
    /// Check if the user is currently available for trading.
    pub fn is_available(&self) -> bool {
        self.status.is_available()
    }

    /// Check if the user is banned.
    pub fn is_banned(&self) -> bool {
        self.banned.unwrap_or(false)
    }
}

/// User achievement display.
#[derive(Debug, Clone, Deserialize)]
pub struct Achievement {
    /// Achievement ID
    pub id: String,

    /// Path to achievement icon
    pub icon: String,

    /// Path to achievement thumbnail
    #[serde(default)]
    pub thumb: Option<String>,

    /// Achievement type
    #[serde(rename = "type")]
    pub achievement_type: AchievementType,

    /// Localized achievement content
    #[serde(default)]
    pub i18n: Option<AchievementTranslation>,
}

/// Achievement type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum AchievementType {
    Patreon,
    Github,
    Custom,
}

/// Localized achievement content.
#[derive(Debug, Clone, Deserialize)]
pub struct AchievementTranslation {
    /// Achievement name
    pub name: String,

    /// Achievement description
    pub description: String,
}

/// Private user profile (returned from /me endpoint).
///
/// Contains all public profile data plus private settings and account info.
#[derive(Debug, Clone, Deserialize)]
pub struct UserPrivate {
    /// Unique user identifier
    pub id: String,

    /// In-game name (IGN)
    #[serde(rename = "ingameName")]
    pub ingame_name: String,

    /// URL-friendly identifier
    pub slug: String,

    /// Path to user avatar
    #[serde(default)]
    pub avatar: Option<String>,

    /// Path to profile background
    #[serde(default)]
    pub background: Option<String>,

    /// Profile description (may contain HTML)
    #[serde(default)]
    pub about: Option<String>,

    /// User reputation score
    #[serde(default)]
    pub reputation: i32,

    /// In-game mastery rank
    #[serde(rename = "masteryLevel", default)]
    pub mastery_level: Option<u32>,

    /// User's gaming platform
    pub platform: Platform,

    /// Whether cross-play is enabled
    #[serde(default)]
    pub crossplay: bool,

    /// Preferred locale
    #[serde(default)]
    pub locale: Option<String>,

    /// Featured achievements on profile
    #[serde(rename = "achievementShowcase", default)]
    pub achievement_showcase: Vec<Achievement>,

    /// Current online status
    #[serde(rename = "status", default)]
    pub status: UserStatus,

    /// Current in-game activity
    #[serde(default)]
    pub activity: Option<Activity>,

    /// Last seen timestamp
    #[serde(rename = "lastSeen", default)]
    pub last_seen: Option<DateTime<Utc>>,

    /// Whether the user is banned
    #[serde(default)]
    pub banned: Option<bool>,

    /// Ban expiration time
    #[serde(rename = "banUntil", default)]
    pub ban_until: Option<DateTime<Utc>>,

    /// Ban reason message
    #[serde(rename = "banMessage", default)]
    pub ban_message: Option<String>,

    /// Whether the user has an active warning
    #[serde(default)]
    pub warned: Option<bool>,

    /// Warning message
    #[serde(rename = "warnMessage", default)]
    pub warn_message: Option<String>,

    /// Email address
    #[serde(default)]
    pub email: Option<String>,

    /// User role on the site
    #[serde(default)]
    pub role: UserRole,

    /// Subscription tier
    #[serde(default)]
    pub tier: Option<SubscriptionTier>,

    /// UI theme preference
    #[serde(default)]
    pub theme: Option<Theme>,

    /// Whether to sync locale across devices
    #[serde(rename = "syncLocale", default)]
    pub sync_locale: Option<bool>,

    /// Whether to sync theme across devices
    #[serde(rename = "syncTheme", default)]
    pub sync_theme: Option<bool>,

    /// Whether account is verified
    #[serde(default)]
    pub verified: Option<bool>,
}

impl UserPrivate {
    /// Check if the user is currently available for trading.
    pub fn is_available(&self) -> bool {
        self.status.is_available()
    }

    /// Check if the user is banned.
    pub fn is_banned(&self) -> bool {
        self.banned.unwrap_or(false)
    }

    /// Check if the user has an active warning.
    pub fn has_warning(&self) -> bool {
        self.warned.unwrap_or(false)
    }

    /// Check if the user is verified.
    pub fn is_verified(&self) -> bool {
        self.verified.unwrap_or(false)
    }

    /// Check if the user is a moderator or admin.
    pub fn is_staff(&self) -> bool {
        matches!(self.role, UserRole::Moderator | UserRole::Admin)
    }

    /// Convert to public user profile.
    pub fn to_profile(&self) -> UserProfile {
        UserProfile {
            id: self.id.clone(),
            ingame_name: self.ingame_name.clone(),
            slug: self.slug.clone(),
            avatar: self.avatar.clone(),
            background: self.background.clone(),
            about: self.about.clone(),
            reputation: self.reputation,
            mastery_level: self.mastery_level,
            platform: self.platform,
            crossplay: self.crossplay,
            locale: self.locale.clone(),
            status: self.status,
            activity: self.activity.clone(),
            last_seen: self.last_seen,
            achievement_showcase: self.achievement_showcase.clone(),
            banned: self.banned,
            ban_until: self.ban_until,
            ban_message: self.ban_message.clone(),
            warned: self.warned,
            warn_message: self.warn_message.clone(),
        }
    }
}

/// Request to update the current user's profile.
///
/// Only include the fields you want to change.
///
/// # Example
///
/// ```
/// use wf_market::{UpdateProfile, Platform, Theme};
///
/// // Update platform and enable crossplay
/// let update = UpdateProfile::new()
///     .platform(Platform::Pc)
///     .crossplay(true);
///
/// // Update theme preference
/// let update = UpdateProfile::new().theme(Theme::Dark);
///
/// // Update profile description
/// let update = UpdateProfile::new().about("Trading Prime parts!");
/// ```
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateProfile {
    /// New profile description
    #[serde(skip_serializing_if = "Option::is_none")]
    pub about: Option<String>,

    /// New platform
    #[serde(skip_serializing_if = "Option::is_none")]
    pub platform: Option<Platform>,

    /// Enable/disable crossplay
    #[serde(skip_serializing_if = "Option::is_none")]
    pub crossplay: Option<bool>,

    /// New locale
    #[serde(skip_serializing_if = "Option::is_none")]
    pub locale: Option<Language>,

    /// New theme preference
    #[serde(skip_serializing_if = "Option::is_none")]
    pub theme: Option<Theme>,

    /// Sync locale across devices
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sync_locale: Option<bool>,

    /// Sync theme across devices
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sync_theme: Option<bool>,
}

impl UpdateProfile {
    /// Create a new empty profile update request.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the profile description.
    pub fn about(mut self, about: impl Into<String>) -> Self {
        self.about = Some(about.into());
        self
    }

    /// Set the platform.
    pub fn platform(mut self, platform: Platform) -> Self {
        self.platform = Some(platform);
        self
    }

    /// Set crossplay enabled/disabled.
    pub fn crossplay(mut self, crossplay: bool) -> Self {
        self.crossplay = Some(crossplay);
        self
    }

    /// Set the locale.
    pub fn locale(mut self, locale: Language) -> Self {
        self.locale = Some(locale);
        self
    }

    /// Set the theme preference.
    pub fn theme(mut self, theme: Theme) -> Self {
        self.theme = Some(theme);
        self
    }

    /// Set whether to sync locale across devices.
    pub fn sync_locale(mut self, sync: bool) -> Self {
        self.sync_locale = Some(sync);
        self
    }

    /// Set whether to sync theme across devices.
    pub fn sync_theme(mut self, sync: bool) -> Self {
        self.sync_theme = Some(sync);
        self
    }

    /// Check if any fields are set.
    pub fn is_empty(&self) -> bool {
        self.about.is_none()
            && self.platform.is_none()
            && self.crossplay.is_none()
            && self.locale.is_none()
            && self.theme.is_none()
            && self.sync_locale.is_none()
            && self.sync_theme.is_none()
    }
}

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

    #[test]
    fn test_user_is_available() {
        let user = User {
            id: "test".to_string(),
            ingame_name: "TestUser".to_string(),
            avatar: None,
            reputation: 0,
            locale: None,
            platform: Platform::Pc,
            crossplay: true,
            status: UserStatus::Online,
            activity: None,
            last_seen: None,
        };

        assert!(user.is_available());
    }

    #[test]
    fn test_user_offline_not_available() {
        let user = User {
            id: "test".to_string(),
            ingame_name: "TestUser".to_string(),
            avatar: None,
            reputation: 0,
            locale: None,
            platform: Platform::Pc,
            crossplay: true,
            status: UserStatus::Offline,
            activity: None,
            last_seen: None,
        };

        assert!(!user.is_available());
    }
}