use serde::{Deserialize, Serialize};

/// Browser environment data collected by the 3DS Method or JS snippet.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BrowserInfo {
    /// Whether Java is enabled.
    pub browser_java_enabled: bool,
    /// Whether JavaScript is enabled.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_java_script_enabled: Option<bool>,
    /// Value representing the browser language (IETF BCP47, e.g. "en-GB").
    pub browser_language: String,
    /// Colour depth of the browser screen (1, 4, 8, 15, 16, 24, 32, 48).
    pub browser_color_depth: String,
    /// Screen height in pixels.
    pub browser_screen_height: String,
    /// Screen width in pixels.
    pub browser_screen_width: String,
    /// Time-zone offset in minutes (e.g. -60 for UTC+1).
    pub browser_tz: String,
    /// HTTP Accept header sent by the browser.
    pub browser_accept_header: String,
    /// User-agent string of the browser.
    pub browser_user_agent: String,
    /// IP address of the browser (v4 or v6).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_ip: Option<String>,
}

/// SDK-collected device data (app channel).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SdkInfo {
    /// Unique ID for the app install (UUIDv4).
    pub sdk_app_id: String,
    /// Ephemeral public key generated by the SDK for this transaction.
    pub sdk_ephem_pub_key: serde_json::Value,
    /// Reference number for the 3DS SDK.
    pub sdk_reference_number: String,
    /// Unique transaction identifier generated by the SDK (UUIDv4).
    pub sdk_trans_id: String,
    /// JWE-encrypted device data blob.
    pub sdk_enc_data: String,
    /// Maximum timeout in minutes for SDK challenge.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sdk_max_timeout: Option<u8>,
}

/// SDK UI rendering capabilities.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeviceRenderOptions {
    /// SDK interface types supported.
    pub sdk_interface: SdkInterface,
    /// UI types supported.
    pub sdk_ui_type: Vec<UiType>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SdkInterface {
    #[serde(rename = "01")]
    Native,
    #[serde(rename = "02")]
    Html,
    #[serde(rename = "03")]
    Both,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum UiType {
    #[serde(rename = "01")]
    Text,
    #[serde(rename = "02")]
    SingleSelect,
    #[serde(rename = "03")]
    MultiSelect,
    #[serde(rename = "04")]
    Oob,
    #[serde(rename = "05")]
    HtmlOther,
}
