    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

    // use serde::{Deserialize, Serialize};

    #[derive(Clone)]
    pub enum UserAction {
        Access,
        Log(String),
        Request(String),
        View(String),
        List(String),
        Profile(String),
        Other,
    }
    impl Default for UserAction {
        fn default() -> Self {
            UserAction::Other
        }
    }
    impl std::fmt::Display for UserAction {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            match self {
               UserAction::Access => write!(f,"access"),
               UserAction::Log(info) =>write!(f,"log: {}", info),
               UserAction::Request(info) =>write!(f,"request: {}", info),
               UserAction::View(info) => write!(f,"view: {}", info),
               UserAction::List(info) => write!(f,"list: {}", info),
               UserAction::Profile( info) => write!(f,"profile: {}", info),
               UserAction::Other => write!(f,"other"),
            }
        }
    }
    impl UserAction {
        #[allow(dead_code)]
        pub fn from_str(value: &str, info: String) -> UserAction {
            match value {
                "access" | "Access" => UserAction::Access,
                "log" | "Log" => UserAction::Log(info),
                "request" | "Request" => UserAction::Request(info),
                "view" | "View" => UserAction::View(info),
                "list" | "List" => UserAction::List(info),
                "profile" | "Profile " => UserAction::Profile(info),
                "other" | "Other " => UserAction::Other,
                _ => UserAction::default(),
            }
        }
        #[allow(dead_code)]
        pub fn info(&self) -> String {
            match self {
                UserAction::Access => String::from(""),
                UserAction::Log(info) => info.to_owned(),
                UserAction::Request(info) => info.to_owned(),
                UserAction::View(info) => info.to_owned(),
                UserAction::List(info) => info.to_owned(),
                UserAction::Profile(info) => info.to_owned(),
                UserAction::Other => String::from(""),
            }
        }
    }