Skip to main content

knowdit_kg_model/
audit_finding.rs

1use schemars::JsonSchema;
2use sea_orm::entity::prelude::*;
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6#[derive(
7    Debug,
8    Clone,
9    Copy,
10    PartialEq,
11    Eq,
12    Hash,
13    EnumIter,
14    DeriveActiveEnum,
15    Serialize,
16    Deserialize,
17    JsonSchema,
18)]
19#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(16))")]
20pub enum FindingSeverity {
21    #[sea_orm(string_value = "High")]
22    High,
23    #[sea_orm(string_value = "Medium")]
24    Medium,
25    #[sea_orm(string_value = "Low")]
26    Low,
27}
28
29impl FindingSeverity {
30    pub fn as_str(&self) -> &'static str {
31        match self {
32            Self::High => "High",
33            Self::Medium => "Medium",
34            Self::Low => "Low",
35        }
36    }
37
38    pub fn rank(&self) -> u8 {
39        match self {
40            Self::High => 3,
41            Self::Medium => 2,
42            Self::Low => 1,
43        }
44    }
45
46    pub fn max(self, other: Self) -> Self {
47        if self.rank() >= other.rank() {
48            self
49        } else {
50            other
51        }
52    }
53}
54
55impl fmt::Display for FindingSeverity {
56    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57        f.write_str(self.as_str())
58    }
59}