use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Identity {
pub id: Option<u64>,
pub device_model: Option<String>,
pub has_battery: bool,
pub has_mouse: bool,
pub has_touch: bool,
pub os: Os,
pub os_version: String,
pub platform: PlatformInfo,
pub browser: Browser,
pub browser_version: Vec<u16>,
pub screen: ScreenResolution,
pub hardware_concurrency: u8,
pub memory: u8,
pub gpu: Gpu,
pub language: Vec<String>,
pub history_count: Option<u16>,
pub proxy: Option<String>,
pub timezone: Option<String>,
}
impl Identity {
pub fn from_json(s: &str) -> Result<Self, serde_json::Error> {
serde_json::from_str(s)
}
#[cfg(feature = "bson")]
pub fn from_bson(doc: bson::Document) -> Result<Self, bson::de::Error> {
bson::from_document(doc)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlatformInfo {
pub bitness: Option<String>,
pub architecture: Option<String>,
pub navigator_platform: NavigatorPlatform,
pub version: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum NavigatorPlatform {
#[serde(rename = "Win32")]
Win32,
#[serde(rename = "MacIntel")]
MacIntel,
#[serde(rename = "Linux x86_64")]
LinuxX86_64,
#[serde(rename = "Linux armv81")]
LinuxArmV81,
#[serde(rename = "iPhone")]
IPhone,
Other(String),
}
impl NavigatorPlatform {
pub fn as_str(&self) -> &str {
match self {
Self::Win32 => "Win32",
Self::MacIntel => "MacIntel",
Self::LinuxX86_64 => "Linux x86_64",
Self::LinuxArmV81 => "Linux armv81",
Self::IPhone => "iPhone",
Self::Other(s) => s.as_str(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScreenResolution {
pub logical_width: u16,
pub logical_height: u16,
pub original_width: u16,
pub original_height: u16,
pub density_pixel_ratio: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Gpu {
pub vendor: String,
pub webgl_renderer: String,
pub webgl_vendor: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Os {
Windows,
Macintosh,
Linux,
Android,
Ios,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Browser {
Chrome,
Safari,
Edge,
}