use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
use crate::models;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum PolicyType {
TwoFactorAuthentication,
MasterPassword,
PasswordGenerator,
SingleOrg,
RequireSso,
OrganizationDataOwnership,
DisableSend,
SendOptions,
ResetPassword,
MaximumVaultTimeout,
DisablePersonalVaultExport,
ActivateAutofill,
AutomaticAppLogIn,
FreeFamiliesSponsorshipPolicy,
RemoveUnlockWithPin,
RestrictedItemTypesPolicy,
UriMatchDefaults,
AutotypeDefaultSetting,
AutomaticUserConfirmation,
BlockClaimedDomainAccountCreation,
OrganizationUserNotification,
SendControls,
__Unknown(i64),
}
impl PolicyType {
pub fn as_i64(&self) -> i64 {
match self {
Self::TwoFactorAuthentication => 0,
Self::MasterPassword => 1,
Self::PasswordGenerator => 2,
Self::SingleOrg => 3,
Self::RequireSso => 4,
Self::OrganizationDataOwnership => 5,
Self::DisableSend => 6,
Self::SendOptions => 7,
Self::ResetPassword => 8,
Self::MaximumVaultTimeout => 9,
Self::DisablePersonalVaultExport => 10,
Self::ActivateAutofill => 11,
Self::AutomaticAppLogIn => 12,
Self::FreeFamiliesSponsorshipPolicy => 13,
Self::RemoveUnlockWithPin => 14,
Self::RestrictedItemTypesPolicy => 15,
Self::UriMatchDefaults => 16,
Self::AutotypeDefaultSetting => 17,
Self::AutomaticUserConfirmation => 18,
Self::BlockClaimedDomainAccountCreation => 19,
Self::OrganizationUserNotification => 20,
Self::SendControls => 21,
Self::__Unknown(v) => *v,
}
}
pub fn from_i64(value: i64) -> Self {
match value {
0 => Self::TwoFactorAuthentication,
1 => Self::MasterPassword,
2 => Self::PasswordGenerator,
3 => Self::SingleOrg,
4 => Self::RequireSso,
5 => Self::OrganizationDataOwnership,
6 => Self::DisableSend,
7 => Self::SendOptions,
8 => Self::ResetPassword,
9 => Self::MaximumVaultTimeout,
10 => Self::DisablePersonalVaultExport,
11 => Self::ActivateAutofill,
12 => Self::AutomaticAppLogIn,
13 => Self::FreeFamiliesSponsorshipPolicy,
14 => Self::RemoveUnlockWithPin,
15 => Self::RestrictedItemTypesPolicy,
16 => Self::UriMatchDefaults,
17 => Self::AutotypeDefaultSetting,
18 => Self::AutomaticUserConfirmation,
19 => Self::BlockClaimedDomainAccountCreation,
20 => Self::OrganizationUserNotification,
21 => Self::SendControls,
v => Self::__Unknown(v),
}
}
}
impl serde::Serialize for PolicyType {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_i64(self.as_i64())
}
}
impl<'de> serde::Deserialize<'de> for PolicyType {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct PolicyTypeVisitor;
impl Visitor<'_> for PolicyTypeVisitor {
type Value = PolicyType;
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str("an integer")
}
fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
Ok(PolicyType::from_i64(v))
}
fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
Ok(PolicyType::from_i64(v as i64))
}
}
deserializer.deserialize_i64(PolicyTypeVisitor)
}
}
impl std::fmt::Display for PolicyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_i64())
}
}
impl Default for PolicyType {
fn default() -> PolicyType {
Self::TwoFactorAuthentication
}
}