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
640
641
642
643
use std::convert::TryFrom;

use serde::{Serialize, Deserialize};

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "u8", into = "u8")]
pub enum PrivacySetting {
    Private,
    Buddies,
    Anyone,
}

impl TryFrom<u8> for PrivacySetting {
    type Error = &'static str;

    fn try_from(val: u8) -> Result<PrivacySetting, Self::Error> {
        match val {
            0 => Ok(PrivacySetting::Private),
            1 => Ok(PrivacySetting::Buddies),
            2 => Ok(PrivacySetting::Anyone),
            _ => Err("Cannot convert u8 into PrivacySetting")
        }
    }
}

impl Into<u8> for PrivacySetting {
    fn into(self) -> u8 {
        match self {
            PrivacySetting::Private => 0,
            PrivacySetting::Buddies => 1,
            PrivacySetting::Anyone => 2,
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "&str", into = "&'static str")]
pub enum ProjectStatus {
    Prepping,
    InProgress,
    Drafted,
    Completed,
    Published,
}

impl TryFrom<&str> for ProjectStatus {
    type Error = &'static str;

    fn try_from(val: &str) -> Result<ProjectStatus, Self::Error> {
        match val {
            "Prepping" => Ok(ProjectStatus::Prepping),
            "In Progress" => Ok(ProjectStatus::InProgress),
            "Drafted" => Ok(ProjectStatus::Drafted),
            "Completed" => Ok(ProjectStatus::Completed),
            "Published" => Ok(ProjectStatus::Published),
            _ => Err("Cannot convert &str into ProjectStatus")
        }
    }
}

impl Into<&'static str> for ProjectStatus {
    fn into(self) -> &'static str {
        match self {
            ProjectStatus::Prepping => "Prepping",
            ProjectStatus::InProgress => "In Progress",
            ProjectStatus::Drafted => "Drafted",
            ProjectStatus::Completed => "Completed",
            ProjectStatus::Published => "Published",
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "u8", into = "u8")]
pub enum EventType {
    NanoWrimo,
    CampNano,
    Custom,
}

impl TryFrom<u8> for EventType {
    type Error = &'static str;

    fn try_from(val: u8) -> Result<EventType, Self::Error> {
        match val {
            0 => Ok(EventType::NanoWrimo),
            1 => Ok(EventType::CampNano),
            2 => Ok(EventType::Custom),
            _ => Err("Cannot convert u8 into EventType")
        }
    }
}

impl Into<u8> for EventType {
    fn into(self) -> u8 {
        match self {
            EventType::NanoWrimo => 0,
            EventType::CampNano => 1,
            EventType::Custom => 2,
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "&str", into = "&'static str")]
pub enum GroupType {
    Everyone,
    Region,
    Buddies,
    WritingGroup,
    Event,
}

impl TryFrom<&str> for GroupType {
    type Error = &'static str;

    fn try_from(val: &str) -> Result<GroupType, Self::Error> {
        match val {
            "everyone" => Ok(GroupType::Everyone),
            "region" => Ok(GroupType::Region),
            "buddies" => Ok(GroupType::Buddies),
            "writing group" => Ok(GroupType::WritingGroup),
            "event" => Ok(GroupType::Event),
            _ => Err("Cannot convert &str into GroupType")
        }
    }
}

impl Into<&'static str> for GroupType {
    fn into(self) -> &'static str {
        match self {
            GroupType::Everyone => "everyone",
            GroupType::Region => "region",
            GroupType::Buddies => "buddies",
            GroupType::WritingGroup => "writing group",
            GroupType::Event => "event",
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "&str", into = "&'static str")]
pub enum EntryMethod {
    Join,
    Creator,
    Create,
    Invited,
    Blocked,
}

impl TryFrom<&str> for EntryMethod {
    type Error = &'static str;

    fn try_from(val: &str) -> Result<EntryMethod, Self::Error> {
        match val {
            "join" => Ok(EntryMethod::Join),
            "creator" => Ok(EntryMethod::Creator),
            "create" => Ok(EntryMethod::Create),
            "invited" => Ok(EntryMethod::Invited),
            "blocked" => Ok(EntryMethod::Blocked),
            _ => Err("Cannot convert &str into EntryMethod")
        }
    }
}

impl Into<&'static str> for EntryMethod {
    fn into(self) -> &'static str {
        match self {
            EntryMethod::Join => "join",
            EntryMethod::Creator => "creator",
            EntryMethod::Create => "create",
            EntryMethod::Invited => "invited",
            EntryMethod::Blocked => "blocked",
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "u8", into = "u8")]
pub enum AdminLevel {
    User,
    Admin
}

impl TryFrom<u8> for AdminLevel {
    type Error = &'static str;

    fn try_from(val: u8) ->  Result<AdminLevel, Self::Error> {
        match val {
            0 => Ok(AdminLevel::User),
            1 => Ok(AdminLevel::Admin),
            _ => Err("Cannot convert u8 into AdminLevel")
        }
    }
}

impl Into<u8> for AdminLevel {
    fn into(self) -> u8 {
        match self {
            AdminLevel::User => 0,
            AdminLevel::Admin => 1,
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "&str", into = "&'static str")]
pub enum ActionType {
    BadgeAwarded,
    BuddiesPage,
    NanoMessages,
    ProjectsPage,
}

impl TryFrom<&str> for ActionType {
    type Error = &'static str;

    fn try_from(val: &str) -> Result<ActionType, Self::Error> {
        match val {
            "BADGE_AWARDED" => Ok(ActionType::BadgeAwarded),
            "BUDDIES_PAGE" => Ok(ActionType::BuddiesPage),
            "NANOMESSAGES" => Ok(ActionType::NanoMessages),
            "PROJECTS_PAGE" => Ok(ActionType::ProjectsPage),
            _ => Err("Cannot convert &str into ActionType")
        }
    }
}

impl Into<&'static str> for ActionType {
    fn into(self) -> &'static str {
        match self {
            ActionType::BadgeAwarded => "BADGE_AWARDED",
            ActionType::BuddiesPage => "BUDDIES_PAGE",
            ActionType::NanoMessages => "NANOMESSAGES",
            ActionType::ProjectsPage => "PROJECTS_PAGE"
        }
    }
}

/// Whether to display the notification in the 'recent notifications'
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "u8", into = "u8")]
pub enum DisplayStatus {
    AllNotifs,
    RecentNotifs,
}

impl TryFrom<u8> for DisplayStatus {
    type Error = &'static str;

    fn try_from(val: u8) ->  Result<DisplayStatus, Self::Error> {
        match val {
            0 => Ok(DisplayStatus::AllNotifs),
            1 => Ok(DisplayStatus::RecentNotifs),
            _ => Err("Cannot convert u8 into DisplayStatus")
        }
    }
}

impl Into<u8> for DisplayStatus {
    fn into(self) -> u8 {
        match self {
            DisplayStatus::AllNotifs => 0,
            DisplayStatus::RecentNotifs => 1,
        }
    }
}

// TODO: This may be wrong
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "u8", into = "u8")]
pub enum WritingType {
    Novel,
    ShortStories,
    Memoir,
    Script,
    Nonfiction,
    Poetry,
    Other
}

impl TryFrom<u8> for WritingType {
    type Error = &'static str;

    fn try_from(val: u8) ->  Result<WritingType, Self::Error> {
        match val {
            0 => Ok(WritingType::Novel),
            1 => Ok(WritingType::ShortStories),
            2 => Ok(WritingType::Memoir),
            3 => Ok(WritingType::Script),
            4 => Ok(WritingType::Nonfiction),
            5 => Ok(WritingType::Poetry),
            6 => Ok(WritingType::Other),
            _ => Err("Cannot convert u8 into WritingType")
        }
    }
}

impl Into<u8> for WritingType {
    fn into(self) -> u8 {
        match self {
            WritingType::Novel => 0,
            WritingType::ShortStories => 1,
            WritingType::Memoir => 2,
            WritingType::Script => 3,
            WritingType::Nonfiction => 4,
            WritingType::Poetry => 5,
            WritingType::Other => 8
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "&str", into = "&'static str")]
pub enum ContentType {
    GeneralContent,
    StackedContent,
    Plate,
    GroupOfPeople,
    GroupOfPageCards,
    PersonCard,
    PepTalk,
    PlainText,
}

impl TryFrom<&str> for ContentType {
    type Error = &'static str;

    fn try_from(val: &str) -> Result<ContentType, Self::Error> {
        match val {
            "General content" => Ok(ContentType::GeneralContent),
            "Stacked Content" => Ok(ContentType::StackedContent),
            "Plate" => Ok(ContentType::Plate),
            "Group of people" => Ok(ContentType::GroupOfPeople),
            "Group of page cards" => Ok(ContentType::GroupOfPageCards),
            "Person Card" => Ok(ContentType::PersonCard),
            "Pep Talk" => Ok(ContentType::PepTalk),
            "Plain Text" => Ok(ContentType::PlainText),
            _ => Err("Cannot convert &str into ContentType")
        }
    }
}

impl Into<&'static str> for ContentType {
    fn into(self) -> &'static str {
        match self {
            ContentType::GeneralContent => "General content",
            ContentType::StackedContent => "Stacked Content",
            ContentType::Plate => "Plate",
            ContentType::GroupOfPeople => "Group of people",
            ContentType::GroupOfPageCards => "Group of page cards",
            ContentType::PersonCard => "Person Card",
            ContentType::PepTalk => "Pep Talk",
            ContentType::PlainText => "Plain Text",
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "&str", into = "&'static str")]
pub enum RegistrationPath {
    Email,
    Facebook,
    Google,
}

impl TryFrom<&str> for RegistrationPath {
    type Error = &'static str;

    fn try_from(val: &str) -> Result<RegistrationPath, Self::Error> {
        match val {
            "email" => Ok(RegistrationPath::Email),
            "Facebook" => Ok(RegistrationPath::Facebook),
            "Google" => Ok(RegistrationPath::Google),
            _ => Err("Cannot convert &str into RegistrationPath")
        }
    }
}

impl Into<&'static str> for RegistrationPath {
    fn into(self) -> &'static str {
        match self {
            RegistrationPath::Email => "email",
            RegistrationPath::Facebook => "Facebook",
            RegistrationPath::Google => "Google",
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "&str", into = "&'static str")]
pub enum BadgeType {
    WordCount,
    SelfAwarded,
    Participation
}

impl TryFrom<&str> for BadgeType {
    type Error = &'static str;

    fn try_from(val: &str) -> Result<BadgeType, Self::Error> {
        match val {
            "word count" => Ok(BadgeType::WordCount),
            "self-awarded" => Ok(BadgeType::SelfAwarded),
            "participation" => Ok(BadgeType::Participation),
            _ => Err("Cannot convert &str into BadgeType")
        }
    }
}

impl Into<&'static str> for BadgeType {
    fn into(self) -> &'static str {
        match self {
            BadgeType::WordCount => "word count",
            BadgeType::SelfAwarded => "self-awarded",
            BadgeType::Participation => "participation",
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "u8", into = "u8")]
pub enum JoiningRule {
    AdminOnly,
    AnyUser,
}

impl TryFrom<u8> for JoiningRule {
    type Error = &'static str;

    fn try_from(val: u8) -> Result<JoiningRule, Self::Error> {
        match val {
            0 => Ok(JoiningRule::AdminOnly),
            1 => Ok(JoiningRule::AnyUser),
            _ => Err("Cannot convert u8 into JoiningRule")
        }
    }
}

impl Into<u8> for JoiningRule {
    fn into(self) -> u8 {
        match self {
            JoiningRule::AdminOnly => 0,
            JoiningRule::AnyUser => 1,
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "u8", into = "u8")]
pub enum UnitType {
    Words,
    Hours
}

impl TryFrom<u8> for UnitType {
    type Error = &'static str;

    fn try_from(val: u8) -> Result<UnitType, Self::Error> {
        match val {
            0 => Ok(UnitType::Words),
            1 => Ok(UnitType::Hours),
            _ => Err("Cannot convert u8 into UnitType")
        }
    }
}

impl Into<u8> for UnitType {
    fn into(self) -> u8 {
        match self {
            UnitType::Words => 0,
            UnitType::Hours => 1,
        }
    }
}

// This may someday be replaced with NanoKind
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "&str", into = "&'static str")]
pub enum AdheresTo {
    Unknown,
    User,
    ProjectChallenge,
}

impl TryFrom<&str> for AdheresTo {
    type Error = &'static str;

    fn try_from(val: &str) -> Result<AdheresTo, Self::Error> {
        match val {
            "" => Ok(AdheresTo::Unknown),
            "user" => Ok(AdheresTo::User),
            "project_challenge" => Ok(AdheresTo::ProjectChallenge),
            _ => Err("Cannot convert &str into AdheresTo")
        }
    }
}

impl Into<&'static str> for AdheresTo {
    fn into(self) -> &'static str {
        match self {
            AdheresTo::Unknown => "",
            AdheresTo::User => "user",
            AdheresTo::ProjectChallenge => "project_challenge",
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "u8", into = "u8")]
pub enum Feeling {
    Upset,
    Stressed,
    Okay,
    PrettyGood,
    Great,
}

impl TryFrom<u8> for Feeling {
    type Error = &'static str;

    fn try_from(val: u8) -> Result<Feeling, Self::Error> {
        match val {
            1 => Ok(Feeling::Upset),
            2 => Ok(Feeling::Stressed),
            3 => Ok(Feeling::Okay),
            4 => Ok(Feeling::PrettyGood),
            5 => Ok(Feeling::Great),
            _ => Err("Cannot convert u8 into Feeling")
        }
    }
}

impl Into<u8> for Feeling {
    fn into(self) -> u8 {
        match self {
            Feeling::Upset => 1,
            Feeling::Stressed => 2,
            Feeling::Okay => 3,
            Feeling::PrettyGood => 4,
            Feeling::Great => 5,
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(from = "u8", into = "u8")]
pub enum Where {
    Home,
    Office,
    Library,
    Cafe,
    Other(u8)
}

impl From<u8> for Where {
    fn from(val: u8) -> Where {
        match val {
            0 => Where::Home,
            1 => Where::Office,
            2 => Where::Library,
            3 => Where::Cafe,
            _ => Where::Other(val)
        }
    }
}

impl Into<u8> for Where {
    fn into(self) -> u8 {
        match self {
            Where::Home => 0,
            Where::Office => 1,
            Where::Library => 2,
            Where::Cafe => 3,
            Where::Other(val) => val
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(from = "u8", into = "u8")]
pub enum How {
    ByHand,
    Typewriter,
    Laptop,
    Phone,
    Other(u8)
}

impl From<u8> for How {
    fn from(val: u8) -> How {
        match val {
            0 => How::ByHand,
            1 => How::Typewriter,
            2 => How::Laptop,
            3 => How::Phone,
            _ => How::Other(val)
        }
    }
}

impl Into<u8> for How {
    fn into(self) -> u8 {
        match self {
            How::ByHand => 0,
            How::Typewriter => 1,
            How::Laptop => 2,
            How::Phone => 3,
            How::Other(val) => val
        }
    }
}

#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
#[serde(try_from = "i8", into = "i8")]
pub enum InvitationStatus {
    Blocked,
    Sent,
    Accepted
}

impl TryFrom<i8> for InvitationStatus {
    type Error = &'static str;

    fn try_from(val: i8) -> Result<InvitationStatus, Self::Error> {
        match val {
            -2 => Ok(InvitationStatus::Blocked),
            0 => Ok(InvitationStatus::Sent),
            1 => Ok(InvitationStatus::Accepted),
            _ => Err("Cannot convert i8 into InvitationStatus")
        }
    }
}

impl Into<i8> for InvitationStatus {
    fn into(self) -> i8 {
        match self {
            InvitationStatus::Blocked => -2,
            InvitationStatus::Sent => 0,
            InvitationStatus::Accepted => 1,
        }
    }
}