Skip to main content

bitwarden_api_api/models/
policy_type.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 PolicyType {
17    TwoFactorAuthentication,
18    MasterPassword,
19    PasswordGenerator,
20    SingleOrg,
21    RequireSso,
22    OrganizationDataOwnership,
23    DisableSend,
24    SendOptions,
25    ResetPassword,
26    MaximumVaultTimeout,
27    DisablePersonalVaultExport,
28    ActivateAutofill,
29    AutomaticAppLogIn,
30    FreeFamiliesSponsorshipPolicy,
31    RemoveUnlockWithPin,
32    RestrictedItemTypesPolicy,
33    UriMatchDefaults,
34    AutotypeDefaultSetting,
35    AutomaticUserConfirmation,
36    BlockClaimedDomainAccountCreation,
37
38    /// Unknown value returned from the server. This is used to handle forward compatibility.
39    __Unknown(i64),
40}
41
42impl PolicyType {
43    pub fn as_i64(&self) -> i64 {
44        match self {
45            Self::TwoFactorAuthentication => 0,
46            Self::MasterPassword => 1,
47            Self::PasswordGenerator => 2,
48            Self::SingleOrg => 3,
49            Self::RequireSso => 4,
50            Self::OrganizationDataOwnership => 5,
51            Self::DisableSend => 6,
52            Self::SendOptions => 7,
53            Self::ResetPassword => 8,
54            Self::MaximumVaultTimeout => 9,
55            Self::DisablePersonalVaultExport => 10,
56            Self::ActivateAutofill => 11,
57            Self::AutomaticAppLogIn => 12,
58            Self::FreeFamiliesSponsorshipPolicy => 13,
59            Self::RemoveUnlockWithPin => 14,
60            Self::RestrictedItemTypesPolicy => 15,
61            Self::UriMatchDefaults => 16,
62            Self::AutotypeDefaultSetting => 17,
63            Self::AutomaticUserConfirmation => 18,
64            Self::BlockClaimedDomainAccountCreation => 19,
65            Self::__Unknown(v) => *v,
66        }
67    }
68
69    pub fn from_i64(value: i64) -> Self {
70        match value {
71            0 => Self::TwoFactorAuthentication,
72            1 => Self::MasterPassword,
73            2 => Self::PasswordGenerator,
74            3 => Self::SingleOrg,
75            4 => Self::RequireSso,
76            5 => Self::OrganizationDataOwnership,
77            6 => Self::DisableSend,
78            7 => Self::SendOptions,
79            8 => Self::ResetPassword,
80            9 => Self::MaximumVaultTimeout,
81            10 => Self::DisablePersonalVaultExport,
82            11 => Self::ActivateAutofill,
83            12 => Self::AutomaticAppLogIn,
84            13 => Self::FreeFamiliesSponsorshipPolicy,
85            14 => Self::RemoveUnlockWithPin,
86            15 => Self::RestrictedItemTypesPolicy,
87            16 => Self::UriMatchDefaults,
88            17 => Self::AutotypeDefaultSetting,
89            18 => Self::AutomaticUserConfirmation,
90            19 => Self::BlockClaimedDomainAccountCreation,
91            v => Self::__Unknown(v),
92        }
93    }
94}
95
96impl serde::Serialize for PolicyType {
97    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
98        serializer.serialize_i64(self.as_i64())
99    }
100}
101
102impl<'de> serde::Deserialize<'de> for PolicyType {
103    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
104        struct PolicyTypeVisitor;
105
106        impl Visitor<'_> for PolicyTypeVisitor {
107            type Value = PolicyType;
108
109            fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
110                f.write_str("an integer")
111            }
112
113            fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
114                Ok(PolicyType::from_i64(v))
115            }
116
117            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
118                Ok(PolicyType::from_i64(v as i64))
119            }
120        }
121
122        deserializer.deserialize_i64(PolicyTypeVisitor)
123    }
124}
125
126impl std::fmt::Display for PolicyType {
127    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
128        write!(f, "{}", self.as_i64())
129    }
130}
131impl Default for PolicyType {
132    fn default() -> PolicyType {
133        Self::TwoFactorAuthentication
134    }
135}