Skip to main content

bitwarden_api_api/models/
event_system_user.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14///
15#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum EventSystemUser {
17    Unknown,
18    SCIM,
19    DomainVerification,
20    PublicApi,
21    TwoFactorDisabled,
22    BitwardenPortal,
23
24    /// Unknown value returned from the server. This is used to handle forward compatibility.
25    __Unknown(i64),
26}
27
28impl EventSystemUser {
29    pub fn as_i64(&self) -> i64 {
30        match self {
31            Self::Unknown => 0,
32            Self::SCIM => 1,
33            Self::DomainVerification => 2,
34            Self::PublicApi => 3,
35            Self::TwoFactorDisabled => 4,
36            Self::BitwardenPortal => 5,
37            Self::__Unknown(v) => *v,
38        }
39    }
40
41    pub fn from_i64(value: i64) -> Self {
42        match value {
43            0 => Self::Unknown,
44            1 => Self::SCIM,
45            2 => Self::DomainVerification,
46            3 => Self::PublicApi,
47            4 => Self::TwoFactorDisabled,
48            5 => Self::BitwardenPortal,
49            v => Self::__Unknown(v),
50        }
51    }
52}
53
54impl serde::Serialize for EventSystemUser {
55    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
56        serializer.serialize_i64(self.as_i64())
57    }
58}
59
60impl<'de> serde::Deserialize<'de> for EventSystemUser {
61    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
62        struct EventSystemUserVisitor;
63
64        impl Visitor<'_> for EventSystemUserVisitor {
65            type Value = EventSystemUser;
66
67            fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68                f.write_str("an integer")
69            }
70
71            fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
72                Ok(EventSystemUser::from_i64(v))
73            }
74
75            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
76                Ok(EventSystemUser::from_i64(v as i64))
77            }
78        }
79
80        deserializer.deserialize_i64(EventSystemUserVisitor)
81    }
82}
83
84impl std::fmt::Display for EventSystemUser {
85    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86        write!(f, "{}", self.as_i64())
87    }
88}
89impl Default for EventSystemUser {
90    fn default() -> EventSystemUser {
91        Self::Unknown
92    }
93}