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;
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum PlanType {
    Free,
    FamiliesAnnually2019,
    TeamsMonthly2019,
    TeamsAnnually2019,
    EnterpriseMonthly2019,
    EnterpriseAnnually2019,
    Custom,
    FamiliesAnnually2025,
    TeamsMonthly2020,
    TeamsAnnually2020,
    EnterpriseMonthly2020,
    EnterpriseAnnually2020,
    TeamsMonthly2023,
    TeamsAnnually2023,
    EnterpriseMonthly2023,
    EnterpriseAnnually2023,
    TeamsStarter2023,
    TeamsMonthly,
    TeamsAnnually,
    EnterpriseMonthly,
    EnterpriseAnnually,
    TeamsStarter,
    FamiliesAnnually,

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

impl PlanType {
    pub fn as_i64(&self) -> i64 {
        match self {
            Self::Free => 0,
            Self::FamiliesAnnually2019 => 1,
            Self::TeamsMonthly2019 => 2,
            Self::TeamsAnnually2019 => 3,
            Self::EnterpriseMonthly2019 => 4,
            Self::EnterpriseAnnually2019 => 5,
            Self::Custom => 6,
            Self::FamiliesAnnually2025 => 7,
            Self::TeamsMonthly2020 => 8,
            Self::TeamsAnnually2020 => 9,
            Self::EnterpriseMonthly2020 => 10,
            Self::EnterpriseAnnually2020 => 11,
            Self::TeamsMonthly2023 => 12,
            Self::TeamsAnnually2023 => 13,
            Self::EnterpriseMonthly2023 => 14,
            Self::EnterpriseAnnually2023 => 15,
            Self::TeamsStarter2023 => 16,
            Self::TeamsMonthly => 17,
            Self::TeamsAnnually => 18,
            Self::EnterpriseMonthly => 19,
            Self::EnterpriseAnnually => 20,
            Self::TeamsStarter => 21,
            Self::FamiliesAnnually => 22,
            Self::__Unknown(v) => *v,
        }
    }

    pub fn from_i64(value: i64) -> Self {
        match value {
            0 => Self::Free,
            1 => Self::FamiliesAnnually2019,
            2 => Self::TeamsMonthly2019,
            3 => Self::TeamsAnnually2019,
            4 => Self::EnterpriseMonthly2019,
            5 => Self::EnterpriseAnnually2019,
            6 => Self::Custom,
            7 => Self::FamiliesAnnually2025,
            8 => Self::TeamsMonthly2020,
            9 => Self::TeamsAnnually2020,
            10 => Self::EnterpriseMonthly2020,
            11 => Self::EnterpriseAnnually2020,
            12 => Self::TeamsMonthly2023,
            13 => Self::TeamsAnnually2023,
            14 => Self::EnterpriseMonthly2023,
            15 => Self::EnterpriseAnnually2023,
            16 => Self::TeamsStarter2023,
            17 => Self::TeamsMonthly,
            18 => Self::TeamsAnnually,
            19 => Self::EnterpriseMonthly,
            20 => Self::EnterpriseAnnually,
            21 => Self::TeamsStarter,
            22 => Self::FamiliesAnnually,
            v => Self::__Unknown(v),
        }
    }
}

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

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

        impl Visitor<'_> for PlanTypeVisitor {
            type Value = PlanType;

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

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

        deserializer.deserialize_i64(PlanTypeVisitor)
    }
}

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