bitwarden-api-api 3.0.0

Api bindings for the Bitwarden API.
Documentation
/*
 * Bitwarden Internal API
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: latest
 *
 * Generated by: https://openapi-generator.tech
 */

use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};

use crate::models;
/// PushType :
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum PushType {
    SyncCipherUpdate,
    SyncCipherCreate,
    SyncLoginDelete,
    SyncFolderDelete,
    SyncCiphers,
    SyncVault,
    SyncOrgKeys,
    SyncFolderCreate,
    SyncFolderUpdate,
    SyncCipherDelete,
    SyncSettings,
    LogOut,
    SyncSendCreate,
    SyncSendUpdate,
    SyncSendDelete,
    AuthRequest,
    AuthRequestResponse,
    SyncOrganizations,
    SyncOrganizationStatusChanged,
    SyncOrganizationCollectionSettingChanged,
    Notification,
    NotificationStatus,
    RefreshSecurityTasks,
    OrganizationBankAccountVerified,
    ProviderBankAccountVerified,
    PolicyChanged,
    AutoConfirm,
    PremiumStatusChanged,

    /// Unknown value returned from the server. This is used to handle forward compatibility.
    __Unknown(i64),
}

impl PushType {
    pub fn as_i64(&self) -> i64 {
        match self {
            Self::SyncCipherUpdate => 0,
            Self::SyncCipherCreate => 1,
            Self::SyncLoginDelete => 2,
            Self::SyncFolderDelete => 3,
            Self::SyncCiphers => 4,
            Self::SyncVault => 5,
            Self::SyncOrgKeys => 6,
            Self::SyncFolderCreate => 7,
            Self::SyncFolderUpdate => 8,
            Self::SyncCipherDelete => 9,
            Self::SyncSettings => 10,
            Self::LogOut => 11,
            Self::SyncSendCreate => 12,
            Self::SyncSendUpdate => 13,
            Self::SyncSendDelete => 14,
            Self::AuthRequest => 15,
            Self::AuthRequestResponse => 16,
            Self::SyncOrganizations => 17,
            Self::SyncOrganizationStatusChanged => 18,
            Self::SyncOrganizationCollectionSettingChanged => 19,
            Self::Notification => 20,
            Self::NotificationStatus => 21,
            Self::RefreshSecurityTasks => 22,
            Self::OrganizationBankAccountVerified => 23,
            Self::ProviderBankAccountVerified => 24,
            Self::PolicyChanged => 25,
            Self::AutoConfirm => 26,
            Self::PremiumStatusChanged => 27,
            Self::__Unknown(v) => *v,
        }
    }

    pub fn from_i64(value: i64) -> Self {
        match value {
            0 => Self::SyncCipherUpdate,
            1 => Self::SyncCipherCreate,
            2 => Self::SyncLoginDelete,
            3 => Self::SyncFolderDelete,
            4 => Self::SyncCiphers,
            5 => Self::SyncVault,
            6 => Self::SyncOrgKeys,
            7 => Self::SyncFolderCreate,
            8 => Self::SyncFolderUpdate,
            9 => Self::SyncCipherDelete,
            10 => Self::SyncSettings,
            11 => Self::LogOut,
            12 => Self::SyncSendCreate,
            13 => Self::SyncSendUpdate,
            14 => Self::SyncSendDelete,
            15 => Self::AuthRequest,
            16 => Self::AuthRequestResponse,
            17 => Self::SyncOrganizations,
            18 => Self::SyncOrganizationStatusChanged,
            19 => Self::SyncOrganizationCollectionSettingChanged,
            20 => Self::Notification,
            21 => Self::NotificationStatus,
            22 => Self::RefreshSecurityTasks,
            23 => Self::OrganizationBankAccountVerified,
            24 => Self::ProviderBankAccountVerified,
            25 => Self::PolicyChanged,
            26 => Self::AutoConfirm,
            27 => Self::PremiumStatusChanged,
            v => Self::__Unknown(v),
        }
    }
}

impl serde::Serialize for PushType {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_i64(self.as_i64())
    }
}

impl<'de> serde::Deserialize<'de> for PushType {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct PushTypeVisitor;

        impl Visitor<'_> for PushTypeVisitor {
            type Value = PushType;

            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(PushType::from_i64(v))
            }

            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
                Ok(PushType::from_i64(v as i64))
            }
        }

        deserializer.deserialize_i64(PushTypeVisitor)
    }
}

impl std::fmt::Display for PushType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_i64())
    }
}
impl Default for PushType {
    fn default() -> PushType {
        Self::SyncCipherUpdate
    }
}