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
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
use std::cmp::PartialEq;
use std::fmt::{Display, Formatter};
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

use super::InvalidValueError;

// imports for intra-doc links
#[cfg(doc)]
use super::FedoraRelease;

/// valid `request` values for composes
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ComposeRequest {
    #[serde(rename = "stable")]
    Stable,
    #[serde(rename = "testing")]
    Testing,
}

impl Display for ComposeRequest {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            ComposeRequest::Stable => "stable",
            ComposeRequest::Testing => "testing",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for ComposeRequest {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "stable" => Ok(ComposeRequest::Stable),
            "testing" => Ok(ComposeRequest::Testing),
            _ => Err(InvalidValueError::new("ComposeRequest", value.to_owned())),
        }
    }
}

impl FromStr for ComposeRequest {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


/// valid `state` values for composes
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ComposeState {
    #[serde(rename = "cleaning")]
    Cleaning,
    #[serde(rename = "failed")]
    Failed,
    #[serde(rename = "initializing")]
    Initializing,
    #[serde(rename = "notifying")]
    Notifying,
    #[serde(rename = "pending")]
    Pending,
    #[serde(rename = "punging")]
    Punging,
    #[serde(rename = "requested")]
    Requested,
    #[serde(rename = "signing_repo")]
    SigningRepo,
    #[serde(rename = "success")]
    Success,
    #[serde(rename = "syncing_repo")]
    SyncingRepo,
    #[serde(rename = "updateinfo")]
    UpdateInfo,
}

impl Display for ComposeState {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            ComposeState::Cleaning => "cleaning",
            ComposeState::Failed => "failed",
            ComposeState::Initializing => "initializing",
            ComposeState::Notifying => "notifying",
            ComposeState::Pending => "pending",
            ComposeState::Punging => "punging",
            ComposeState::Requested => "requested",
            ComposeState::SigningRepo => "signing_repo",
            ComposeState::Success => "success",
            ComposeState::SyncingRepo => "syncing_repo",
            ComposeState::UpdateInfo => "updateinfo",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for ComposeState {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "cleaning" => Ok(ComposeState::Cleaning),
            "failed" => Ok(ComposeState::Failed),
            "initializing" => Ok(ComposeState::Initializing),
            "notifying" => Ok(ComposeState::Notifying),
            "pending" => Ok(ComposeState::Pending),
            "punging" => Ok(ComposeState::Punging),
            "requested" => Ok(ComposeState::Requested),
            "signing_repo" => Ok(ComposeState::SigningRepo),
            "success" => Ok(ComposeState::Success),
            "syncing_repo" => Ok(ComposeState::SyncingRepo),
            "updateinfo" => Ok(ComposeState::UpdateInfo),
            _ => Err(InvalidValueError::new("ComposeStatus", value.to_owned())),
        }
    }
}

impl FromStr for ComposeState {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}

/// valid / known content types
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ContentType {
    // tag for container image updates
    #[serde(rename = "container")]
    Container,
    // tag for flatpak updates
    #[serde(rename = "flatpak")]
    Flatpak,
    // tag for module updates
    #[serde(rename = "module")]
    Module,
    // tag for traditional RPM package updates
    #[serde(rename = "rpm")]
    RPM,
}

impl ContentType {
    /// method for returning the [`FedoraRelease`] suffix corresponding to this [`ContentType`]
    pub const fn suffix(&self) -> &str {
        use ContentType::*;

        match self {
            RPM => "",
            Container => "C",
            Flatpak => "F",
            Module => "M",
        }
    }

    /// method for parsing [`FedoraRelease`] suffixes into a [`ContentType`]
    pub fn try_from_suffix(suffix: &str) -> Result<Self, InvalidValueError> {
        match suffix {
            "" => Ok(ContentType::RPM),
            "C" => Ok(ContentType::Container),
            "F" => Ok(ContentType::Flatpak),
            "M" => Ok(ContentType::Module),
            _ => Err(InvalidValueError::new(
                "ContentType",
                format!("Suffix '{suffix}' is not valid."),
            )),
        }
    }
}

impl Display for ContentType {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            ContentType::Container => "container",
            ContentType::Flatpak => "flatpak",
            ContentType::Module => "module",
            ContentType::RPM => "rpm",
        };

        write!(f, "{value}")
    }
}

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

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "container" => Ok(ContentType::Container),
            "flatpak" => Ok(ContentType::Flatpak),
            "module" => Ok(ContentType::Module),
            "rpm" => Ok(ContentType::RPM),
            _ => Err(InvalidValueError::new("ContentType", value.to_owned())),
        }
    }
}

impl FromStr for ContentType {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}

/// valid "karma" values that are associated for update comments and feedback
///
/// Only three values are valid: **-1** for positive feedback, **±0** for neutral (or unspecified)
/// feedback, and **-1** for negative feedback.
///
/// This type uses (de)serializaion support from [`serde_repr`] for converting these three numeric
/// values into the corresponding enum variants.
#[derive(Clone, Copy, Debug, Default, Deserialize_repr, Eq, PartialEq, Serialize_repr)]
#[repr(i8)]
pub enum Karma {
    /// positive feedback
    Positive = 1,
    /// neutral / informational feedback (default)
    #[default]
    Neutral = 0,
    /// negative feedback
    Negative = -1,
}

impl Display for Karma {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Karma::Positive => String::from("+1"),
                Karma::Neutral => String::from("±0"),
                Karma::Negative => String::from("-1"),
            }
        )
    }
}

impl TryFrom<&str> for Karma {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "+1" | "1" => Ok(Karma::Positive),
            "0" | "±0" => Ok(Karma::Neutral),
            "-1" => Ok(Karma::Negative),
            _ => Err(InvalidValueError::new("Karma", value.to_owned())),
        }
    }
}

impl FromStr for Karma {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


/// valid / known package managers
///
/// Values of this type are used to print installation instructions for updates on the server.
#[allow(missing_docs)]
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum PackageManager {
    #[serde(rename = "dnf")]
    DNF,
    #[serde(rename = "unspecified")]
    Unspecified,
    #[serde(rename = "yum")]
    YUM,
}

impl Display for PackageManager {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            PackageManager::DNF => "dnf",
            PackageManager::Unspecified => "unspecified",
            PackageManager::YUM => "yum",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for PackageManager {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "dnf" => Ok(PackageManager::DNF),
            "yum" => Ok(PackageManager::YUM),
            _ => Err(InvalidValueError::new("PackageManager", value.to_owned())),
        }
    }
}

impl FromStr for PackageManager {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


/// valid `state` values for releases
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub enum ReleaseState {
    /// release has been archived after it has reached its EOL
    #[serde(rename = "archived")]
    Archived,
    /// release is currently supported
    #[serde(rename = "current")]
    Current,
    /// release is disabled
    #[serde(rename = "disabled")]
    Disabled,
    /// release is frozen
    #[serde(rename = "frozen")]
    Frozen,
    /// release is in development
    #[serde(rename = "pending")]
    Pending,
}

impl Display for ReleaseState {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            ReleaseState::Archived => "archived",
            ReleaseState::Current => "current",
            ReleaseState::Disabled => "disabled",
            ReleaseState::Frozen => "frozen",
            ReleaseState::Pending => "pending",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for ReleaseState {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "archived" => Ok(ReleaseState::Archived),
            "current" => Ok(ReleaseState::Current),
            "disabled" => Ok(ReleaseState::Disabled),
            "frozen" => Ok(ReleaseState::Frozen),
            "pending" => Ok(ReleaseState::Pending),
            _ => Err(InvalidValueError::new("ReleaseState", value.to_owned())),
        }
    }
}

impl FromStr for ReleaseState {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


/// valid `state` values for an update's gating tests
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub enum TestGatingStatus {
    #[serde(rename = "failed")]
    Failed,
    #[serde(rename = "greenwave_failed")]
    GreenwaveFailed,
    #[serde(rename = "ignored")]
    Ignored,
    #[serde(rename = "passed")]
    Passed,
    #[serde(rename = "queued")]
    Queued,
    #[serde(rename = "running")]
    Running,
    #[serde(rename = "waiting")]
    Waiting,
}

impl Display for TestGatingStatus {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            TestGatingStatus::Failed => "failed",
            TestGatingStatus::GreenwaveFailed => "greenwave_failed",
            TestGatingStatus::Ignored => "ignored",
            TestGatingStatus::Passed => "passed",
            TestGatingStatus::Queued => "queued",
            TestGatingStatus::Running => "running",
            TestGatingStatus::Waiting => "waiting",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for TestGatingStatus {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "failed" => Ok(TestGatingStatus::Failed),
            "greenwave_failed" => Ok(TestGatingStatus::GreenwaveFailed),
            "ignored" => Ok(TestGatingStatus::Ignored),
            "passed" => Ok(TestGatingStatus::Passed),
            "queued" => Ok(TestGatingStatus::Queued),
            "running" => Ok(TestGatingStatus::Running),
            "waiting" => Ok(TestGatingStatus::Waiting),
            _ => Err(InvalidValueError::new("TestGatingStatus", value.to_owned())),
        }
    }
}

impl FromStr for TestGatingStatus {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


// This enum represents the two possible ways to identify a fedora update:
// - internal, numerical ID (only for compatibility with old releases)
// - public, human-readable "alias" (`FEDORA-2019-1A2BB23E`)
#[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub(crate) enum UpdateID {
    // identified via numerical update ID
    ID(u32),
    // identified via update alias
    Alias(String),
}

impl Display for UpdateID {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            UpdateID::ID(number) => number.to_string(),
            UpdateID::Alias(string) => string.to_owned(),
        };

        write!(f, "{value}")
    }
}


/// valid `request` values for updates
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum UpdateRequest {
    /// request for an update to be marked as "obsolete" (usually when another update supersedes it)
    #[serde(rename = "obsolete")]
    Obsolete,
    /// request for the update to be "revoked" or removed
    #[serde(rename = "revoke")]
    Revoke,
    /// request for the update to get pushed to stable
    #[serde(rename = "stable")]
    Stable,
    /// request for the update to get pushed to testing
    #[serde(rename = "testing")]
    Testing,
    /// request for the update to get "unpushed" (removed) from testing
    #[serde(rename = "unpush")]
    Unpush,
}

impl Display for UpdateRequest {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            UpdateRequest::Obsolete => "obsolete",
            UpdateRequest::Revoke => "revoke",
            UpdateRequest::Stable => "stable",
            UpdateRequest::Testing => "testing",
            UpdateRequest::Unpush => "unpush",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for UpdateRequest {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "obsolete" => Ok(UpdateRequest::Obsolete),
            "revoke" => Ok(UpdateRequest::Revoke),
            "stable" => Ok(UpdateRequest::Stable),
            "testing" => Ok(UpdateRequest::Testing),
            "unpush" => Ok(UpdateRequest::Unpush),
            _ => Err(InvalidValueError::new("UpdateRequest", value.to_owned())),
        }
    }
}

impl FromStr for UpdateRequest {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


/// valid `severity` values for updates
///
/// This field is required to not be `Unspecified` for updates with type [`UpdateType::Security`].
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub enum UpdateSeverity {
    #[serde(rename = "high")]
    High,
    #[serde(rename = "low")]
    Low,
    #[serde(rename = "medium")]
    Medium,
    #[default]
    #[serde(rename = "unspecified")]
    Unspecified,
    #[serde(rename = "urgent")]
    Urgent,
}

impl Display for UpdateSeverity {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            UpdateSeverity::High => "high",
            UpdateSeverity::Low => "low",
            UpdateSeverity::Medium => "medium",
            UpdateSeverity::Unspecified => "unspecified",
            UpdateSeverity::Urgent => "urgent",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for UpdateSeverity {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "high" => Ok(UpdateSeverity::High),
            "low" => Ok(UpdateSeverity::Low),
            "medium" => Ok(UpdateSeverity::Medium),
            "unspecified" => Ok(UpdateSeverity::Unspecified),
            "urgent" => Ok(UpdateSeverity::Urgent),
            _ => Err(InvalidValueError::new("UpdateSeverity", value.to_owned())),
        }
    }
}

impl FromStr for UpdateSeverity {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


/// valid `status` values for updates
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum UpdateStatus {
    /// status of updates that have been obsoleted by another update
    #[serde(rename = "obsolete")]
    Obsolete,
    /// status of updates that are pending for either testing or stable
    #[serde(rename = "pending")]
    Pending,
    /// status of updates that are associated with an active side tag
    #[serde(rename = "side_tag_active")]
    SideTagActive,
    /// status of updates that are associated with an expired side tag
    #[serde(rename = "side_tag_expired")]
    SideTagExpired,
    /// status of updates that have been pushed to stable
    #[serde(rename = "stable")]
    Stable,
    /// status of updates that have been pushed to testing
    #[serde(rename = "testing")]
    Testing,
    /// status of updates that have been "unpushed" from testing
    #[serde(rename = "unpushed")]
    Unpushed,
}

impl Display for UpdateStatus {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            UpdateStatus::Obsolete => "obsolete",
            UpdateStatus::Pending => "pending",
            UpdateStatus::SideTagActive => "side_tag_active",
            UpdateStatus::SideTagExpired => "side_tag_expired",
            UpdateStatus::Stable => "stable",
            UpdateStatus::Testing => "testing",
            UpdateStatus::Unpushed => "unpushed",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for UpdateStatus {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "obsolete" => Ok(UpdateStatus::Obsolete),
            "pending" => Ok(UpdateStatus::Pending),
            "side_tag_active" => Ok(UpdateStatus::SideTagActive),
            "side_tag_expired" => Ok(UpdateStatus::SideTagExpired),
            "stable" => Ok(UpdateStatus::Stable),
            "testing" => Ok(UpdateStatus::Testing),
            "unpushed" => Ok(UpdateStatus::Unpushed),
            _ => Err(InvalidValueError::new("UpdateStatus", value.to_owned())),
        }
    }
}

impl FromStr for UpdateStatus {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


/// valid `suggestion` values for updates
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub enum UpdateSuggestion {
    /// recommendation for logging out after this update has been installed
    #[serde(rename = "logout")]
    Logout,
    /// recommendation for rebooting after this update has been installed
    #[serde(rename = "reboot")]
    Reboot,
    /// no recommendation (default)
    #[default]
    #[serde(rename = "unspecified")]
    Unspecified,
}

impl Display for UpdateSuggestion {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            UpdateSuggestion::Logout => "logout",
            UpdateSuggestion::Reboot => "reboot",
            UpdateSuggestion::Unspecified => "unspecified",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for UpdateSuggestion {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "logout" => Ok(UpdateSuggestion::Logout),
            "reboot" => Ok(UpdateSuggestion::Reboot),
            "unspecified" => Ok(UpdateSuggestion::Unspecified),
            _ => Err(InvalidValueError::new("UpdateSuggestion", value.to_owned())),
        }
    }
}

impl FromStr for UpdateSuggestion {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}


/// valid `type` values for updates
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub enum UpdateType {
    /// the update contains fixes for known bugs
    #[serde(rename = "bugfix")]
    BugFix,
    /// the update includes new features or other improvements
    #[serde(rename = "enhancement")]
    Enhancement,
    /// the update includes new packages
    #[serde(rename = "newpackage")]
    NewPackage,
    /// the update includes fixes for security problems
    #[serde(rename = "security")]
    Security,
    /// unspecified type (default)
    #[default]
    #[serde(rename = "unspecified")]
    Unspecified,
}

impl Display for UpdateType {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let value = match self {
            UpdateType::BugFix => "bugfix",
            UpdateType::Enhancement => "enhancement",
            UpdateType::NewPackage => "newpackage",
            UpdateType::Security => "security",
            UpdateType::Unspecified => "unspecified",
        };

        write!(f, "{value}")
    }
}

impl TryFrom<&str> for UpdateType {
    type Error = InvalidValueError;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value.to_lowercase().as_str() {
            "bugfix" => Ok(UpdateType::BugFix),
            "enhancement" => Ok(UpdateType::Enhancement),
            "newpackage" => Ok(UpdateType::NewPackage),
            "security" => Ok(UpdateType::Security),
            "unspecified" => Ok(UpdateType::Unspecified),
            _ => Err(InvalidValueError::new("UpdateType", value.to_owned())),
        }
    }
}

impl FromStr for UpdateType {
    type Err = InvalidValueError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        TryFrom::try_from(s)
    }
}