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
use std::fmt;

use super::HardwareStatus;

pub const CDR_IS_EMPTY: u32 = 6185;
pub const CDR_IS_NOT_EMPTY: u32 = 6186;
pub const CDR_IS_UNKNOWN: u32 = 6187;

/// Represents intermediate stacker status values.
#[repr(u32)]
#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum IntermediateStackerStatus {
    /// Indicates the stacker is empty
    Empty = CDR_IS_EMPTY,
    /// Indicates the stacker is not empty
    NotEmpty = CDR_IS_NOT_EMPTY,
    /// Indicates the stacker status is unknown
    #[default]
    Unknown = CDR_IS_UNKNOWN,
}

impl IntermediateStackerStatus {
    /// Creates a new [IntermediateStackerStatus].
    pub const fn new() -> Self {
        Self::Unknown
    }

    /// Creates a new [IntermediateStackerStatus] from the provided parameter.
    pub const fn create(val: u32) -> Self {
        match val {
            ds if ds == CDR_IS_EMPTY => Self::Empty,
            ds if ds == CDR_IS_NOT_EMPTY => Self::NotEmpty,
            ds if ds == CDR_IS_UNKNOWN => Self::Unknown,
            _ => Self::Unknown,
        }
    }
}

impl From<IntermediateStackerStatus> for HardwareStatus {
    fn from(val: IntermediateStackerStatus) -> Self {
        match val {
            IntermediateStackerStatus::Empty | IntermediateStackerStatus::NotEmpty => {
                Self::Notification
            }
            IntermediateStackerStatus::Unknown => Self::Warning,
        }
    }
}

impl From<IntermediateStackerStatus> for &'static str {
    fn from(val: IntermediateStackerStatus) -> Self {
        match val {
            IntermediateStackerStatus::Empty => "empty",
            IntermediateStackerStatus::NotEmpty => "not empty",
            IntermediateStackerStatus::Unknown => "unknown",
        }
    }
}

impl From<&IntermediateStackerStatus> for &'static str {
    fn from(val: &IntermediateStackerStatus) -> Self {
        (*val).into()
    }
}

impl fmt::Display for IntermediateStackerStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", <&str>::from(self))
    }
}

impl_xfs_enum!(IntermediateStackerStatus, "intermediateStackerStatus");