//! Browser profile configuration

use serde::{Deserialize, Serialize};
use std::path::PathBuf;

fn default_true() -> Option<bool> {
    Some(true)
}

/// Proxy configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProxyConfig {
    /// Proxy server URL
    pub server: String,
    /// Bypass list for proxy
    pub bypass: Option<String>,
    /// Username for proxy authentication
    pub username: Option<String>,
    /// Password for proxy authentication
    pub password: Option<String>,
}

/// Browser profile configuration (streamlined, single source of truth)
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct BrowserProfile {
    /// Whether to run browser in headless mode (defaults to true)
    #[serde(default = "default_true")]
    pub headless: Option<bool>,
    /// Path to user data directory
    pub user_data_dir: Option<PathBuf>,
    /// List of allowed domains
    pub allowed_domains: Option<Vec<String>>,
    /// Path to downloads directory
    pub downloads_path: Option<PathBuf>,
    /// Proxy configuration (for enterprise use)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub proxy: Option<ProxyConfig>,
    /// Enable stealth mode to hide automation fingerprints
    #[serde(default)]
    pub stealth: bool,
    /// Custom user agent string (rotated if multiple provided)
    pub user_agent: Option<String>,
}

impl BrowserProfile {
    /// Create a new BrowserProfile with default settings
    pub fn new() -> Self {
        Self::default()
    }

    /// Set headless mode
    pub fn with_headless(mut self, headless: bool) -> Self {
        self.headless = Some(headless);
        self
    }

    /// Set user data directory
    pub fn with_user_data_dir(mut self, dir: PathBuf) -> Self {
        self.user_data_dir = Some(dir);
        self
    }

    /// Set proxy configuration
    pub fn with_proxy(mut self, proxy: ProxyConfig) -> Self {
        self.proxy = Some(proxy);
        self
    }

    /// Enable stealth mode
    pub fn with_stealth(mut self, stealth: bool) -> Self {
        self.stealth = stealth;
        self
    }

    /// Set custom user agent
    pub fn with_user_agent(mut self, ua: impl Into<String>) -> Self {
        self.user_agent = Some(ua.into());
        self
    }
}
