Skip to main content

bitwarden_api_api/models/
gateway_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 GatewayType {
17    Stripe,
18    Braintree,
19    AppStore,
20    PlayStore,
21    BitPay,
22    PayPal,
23    Bank,
24
25    /// Unknown value returned from the server. This is used to handle forward compatibility.
26    __Unknown(i64),
27}
28
29impl GatewayType {
30    pub fn as_i64(&self) -> i64 {
31        match self {
32            Self::Stripe => 0,
33            Self::Braintree => 1,
34            Self::AppStore => 2,
35            Self::PlayStore => 3,
36            Self::BitPay => 4,
37            Self::PayPal => 5,
38            Self::Bank => 6,
39            Self::__Unknown(v) => *v,
40        }
41    }
42
43    pub fn from_i64(value: i64) -> Self {
44        match value {
45            0 => Self::Stripe,
46            1 => Self::Braintree,
47            2 => Self::AppStore,
48            3 => Self::PlayStore,
49            4 => Self::BitPay,
50            5 => Self::PayPal,
51            6 => Self::Bank,
52            v => Self::__Unknown(v),
53        }
54    }
55}
56
57impl serde::Serialize for GatewayType {
58    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
59        serializer.serialize_i64(self.as_i64())
60    }
61}
62
63impl<'de> serde::Deserialize<'de> for GatewayType {
64    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
65        struct GatewayTypeVisitor;
66
67        impl Visitor<'_> for GatewayTypeVisitor {
68            type Value = GatewayType;
69
70            fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
71                f.write_str("an integer")
72            }
73
74            fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
75                Ok(GatewayType::from_i64(v))
76            }
77
78            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
79                Ok(GatewayType::from_i64(v as i64))
80            }
81        }
82
83        deserializer.deserialize_i64(GatewayTypeVisitor)
84    }
85}
86
87impl std::fmt::Display for GatewayType {
88    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89        write!(f, "{}", self.as_i64())
90    }
91}
92impl Default for GatewayType {
93    fn default() -> GatewayType {
94        Self::Stripe
95    }
96}