/// Browser persona — configurable identity presented to JavaScript.
///
/// Phishing kits fingerprint the browser to detect sandboxes. The persona
/// must be internally consistent: a Chrome UA on Windows should report
/// Win32 platform, en-US language, and realistic screen dimensions.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Persona {
    pub user_agent: String,
    pub platform: String,
    pub language: String,
    pub languages: Vec<String>,
    pub screen_width: u32,
    pub screen_height: u32,
    pub color_depth: u32,
    pub timezone: String,
    pub timezone_offset: i32,
    pub referrer: String,
    pub hardware_concurrency: u32,
    pub device_memory: f64,
    pub max_touch_points: u32,
    pub vendor: String,
    pub app_name: String,
    pub app_version: String,
    pub do_not_track: Option<String>,
}

impl Default for Persona {
    fn default() -> Self {
        Self::chrome_windows()
    }
}

impl Persona {
    /// Chrome 120 on Windows 10. The most common browser configuration.
    pub fn chrome_windows() -> Self {
        Self {
            user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36".into(),
            platform: "Win32".into(),
            language: "en-US".into(),
            languages: vec!["en-US".into(), "en".into()],
            screen_width: 1920,
            screen_height: 1080,
            color_depth: 24,
            timezone: "America/New_York".into(),
            timezone_offset: -300,
            referrer: String::new(),
            hardware_concurrency: 8,
            device_memory: 8.0,
            max_touch_points: 0,
            vendor: "Google Inc.".into(),
            app_name: "Netscape".into(),
            app_version: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36".into(),
            do_not_track: None,
        }
    }

    /// Chrome on macOS. Second most common.
    pub fn chrome_macos() -> Self {
        Self {
            user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36".into(),
            platform: "MacIntel".into(),
            screen_width: 1440,
            screen_height: 900,
            timezone: "America/Los_Angeles".into(),
            timezone_offset: -480,
            ..Self::chrome_windows()
        }
    }

    /// Chrome on Android. Tests mobile-targeted phishing.
    pub fn chrome_android() -> Self {
        Self {
            user_agent: "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36".into(),
            platform: "Linux armv81".into(),
            screen_width: 412,
            screen_height: 915,
            max_touch_points: 5,
            device_memory: 4.0,
            hardware_concurrency: 4,
            ..Self::chrome_windows()
        }
    }

    /// Firefox on Linux. Tests cross-browser compatibility of phishing kits.
    pub fn firefox_linux() -> Self {
        Self {
            user_agent: "Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0"
                .into(),
            platform: "Linux x86_64".into(),
            vendor: String::new(),
            ..Self::chrome_windows()
        }
    }
}
