// DO NOT EDIT
// This file was @generated by Stone

#![allow(
    clippy::too_many_arguments,
    clippy::large_enum_variant,
    clippy::doc_markdown,
)]

/// Possible platforms on which a user may view content.
#[derive(Debug)]
pub enum PlatformType {
    /// The content was viewed on the web.
    Web,
    /// The content was viewed on a desktop client.
    Desktop,
    /// The content was viewed on a mobile iOS client.
    MobileIos,
    /// The content was viewed on a mobile android client.
    MobileAndroid,
    /// The content was viewed from an API client.
    Api,
    /// The content was viewed on an unknown platform.
    Unknown,
    /// The content was viewed on a mobile client. DEPRECATED: Use mobile_ios or mobile_android
    /// instead.
    Mobile,
    /// Catch-all used for unrecognized values returned from the server. Encountering this value
    /// typically indicates that this SDK version is out of date.
    Other,
}

impl<'de> ::serde::de::Deserialize<'de> for PlatformType {
    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        // union deserializer
        use serde::de::{self, MapAccess, Visitor};
        struct EnumVisitor;
        impl<'de> Visitor<'de> for EnumVisitor {
            type Value = PlatformType;
            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
                f.write_str("a PlatformType structure")
            }
            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
                let tag: &str = match map.next_key()? {
                    Some(".tag") => map.next_value()?,
                    _ => return Err(de::Error::missing_field(".tag"))
                };
                match tag {
                    "web" => {
                        crate::eat_json_fields(&mut map)?;
                        Ok(PlatformType::Web)
                    }
                    "desktop" => {
                        crate::eat_json_fields(&mut map)?;
                        Ok(PlatformType::Desktop)
                    }
                    "mobile_ios" => {
                        crate::eat_json_fields(&mut map)?;
                        Ok(PlatformType::MobileIos)
                    }
                    "mobile_android" => {
                        crate::eat_json_fields(&mut map)?;
                        Ok(PlatformType::MobileAndroid)
                    }
                    "api" => {
                        crate::eat_json_fields(&mut map)?;
                        Ok(PlatformType::Api)
                    }
                    "unknown" => {
                        crate::eat_json_fields(&mut map)?;
                        Ok(PlatformType::Unknown)
                    }
                    "mobile" => {
                        crate::eat_json_fields(&mut map)?;
                        Ok(PlatformType::Mobile)
                    }
                    _ => {
                        crate::eat_json_fields(&mut map)?;
                        Ok(PlatformType::Other)
                    }
                }
            }
        }
        const VARIANTS: &[&str] = &["web",
                                    "desktop",
                                    "mobile_ios",
                                    "mobile_android",
                                    "api",
                                    "unknown",
                                    "mobile",
                                    "other"];
        deserializer.deserialize_struct("PlatformType", VARIANTS, EnumVisitor)
    }
}

impl ::serde::ser::Serialize for PlatformType {
    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        // union serializer
        use serde::ser::SerializeStruct;
        match *self {
            PlatformType::Web => {
                // unit
                let mut s = serializer.serialize_struct("PlatformType", 1)?;
                s.serialize_field(".tag", "web")?;
                s.end()
            }
            PlatformType::Desktop => {
                // unit
                let mut s = serializer.serialize_struct("PlatformType", 1)?;
                s.serialize_field(".tag", "desktop")?;
                s.end()
            }
            PlatformType::MobileIos => {
                // unit
                let mut s = serializer.serialize_struct("PlatformType", 1)?;
                s.serialize_field(".tag", "mobile_ios")?;
                s.end()
            }
            PlatformType::MobileAndroid => {
                // unit
                let mut s = serializer.serialize_struct("PlatformType", 1)?;
                s.serialize_field(".tag", "mobile_android")?;
                s.end()
            }
            PlatformType::Api => {
                // unit
                let mut s = serializer.serialize_struct("PlatformType", 1)?;
                s.serialize_field(".tag", "api")?;
                s.end()
            }
            PlatformType::Unknown => {
                // unit
                let mut s = serializer.serialize_struct("PlatformType", 1)?;
                s.serialize_field(".tag", "unknown")?;
                s.end()
            }
            PlatformType::Mobile => {
                // unit
                let mut s = serializer.serialize_struct("PlatformType", 1)?;
                s.serialize_field(".tag", "mobile")?;
                s.end()
            }
            PlatformType::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
        }
    }
}

