// Generated from WebIDL - DO NOT EDIT
// Source: @webref/idl/netinfo

///|
/// Megabit typedef
pub type Megabit = Double

///|
/// Millisecond typedef
pub type Millisecond = Int64

///|
/// ConnectionType enum
pub(all) enum ConnectionType {
  Bluetooth
  Cellular
  Ethernet
  Mixed
  None
  Other
  Unknown
  Wifi
  Wimax
} derive(Eq, Show)

///|
/// Convert to string value
pub fn ConnectionType::to_string(self : ConnectionType) -> String {
  match self {
    ConnectionType::Bluetooth => "bluetooth"
    ConnectionType::Cellular => "cellular"
    ConnectionType::Ethernet => "ethernet"
    ConnectionType::Mixed => "mixed"
    ConnectionType::None => "none"
    ConnectionType::Other => "other"
    ConnectionType::Unknown => "unknown"
    ConnectionType::Wifi => "wifi"
    ConnectionType::Wimax => "wimax"
  }
}

///|
/// Parse from string value
pub fn ConnectionType::from_string(s : String) -> ConnectionType? {
  match s {
    "bluetooth" => Some(ConnectionType::Bluetooth)
    "cellular" => Some(ConnectionType::Cellular)
    "ethernet" => Some(ConnectionType::Ethernet)
    "mixed" => Some(ConnectionType::Mixed)
    "none" => Some(ConnectionType::None)
    "other" => Some(ConnectionType::Other)
    "unknown" => Some(ConnectionType::Unknown)
    "wifi" => Some(ConnectionType::Wifi)
    "wimax" => Some(ConnectionType::Wimax)
    _ => None
  }
}

///|
/// EffectiveConnectionType enum
pub(all) enum EffectiveConnectionType {
  N2g
  N3g
  N4g
  Slow2g
} derive(Eq, Show)

///|
/// Convert to string value
pub fn EffectiveConnectionType::to_string(
  self : EffectiveConnectionType,
) -> String {
  match self {
    EffectiveConnectionType::N2g => "2g"
    EffectiveConnectionType::N3g => "3g"
    EffectiveConnectionType::N4g => "4g"
    EffectiveConnectionType::Slow2g => "slow-2g"
  }
}

///|
/// Parse from string value
pub fn EffectiveConnectionType::from_string(
  s : String,
) -> EffectiveConnectionType? {
  match s {
    "2g" => Some(EffectiveConnectionType::N2g)
    "3g" => Some(EffectiveConnectionType::N3g)
    "4g" => Some(EffectiveConnectionType::N4g)
    "slow-2g" => Some(EffectiveConnectionType::Slow2g)
    _ => None
  }
}

///|
/// NetworkInformation interface
pub type NetworkInformation

///|
pub extern "js" fn NetworkInformation::to_js_value(
  self : NetworkInformation,
) -> JsValue =
  #| (self) => self

///|
/// Cast JsValue to NetworkInformation (unchecked)
pub extern "js" fn NetworkInformation::from_js_value(
  v : JsValue,
) -> NetworkInformation =
  #| (v) => v

///|
/// Safely cast JsValue to NetworkInformation (checked with instanceof)
pub extern "js" fn NetworkInformation::from_js_value_opt(
  v : JsValue,
) -> NetworkInformation? =
  #| (v) => (v instanceof NetworkInformation) ? { $tag: 1, _0: v } : { $tag: 0 }

///|
/// Safely cast JsValue to NetworkInformation (checked with instanceof)
pub extern "js" fn JsValue::as_network_information(
  self : JsValue,
) -> NetworkInformation? =
  #| (self) => (self instanceof NetworkInformation) ? { $tag: 1, _0: self } : { $tag: 0 }

///|
/// Cast JsValue to NetworkInformation (unchecked)
pub extern "js" fn JsValue::to_network_information(
  self : JsValue,
) -> NetworkInformation =
  #| (self) => self

///|
pub extern "js" fn NetworkInformation::to_event_target(
  self : NetworkInformation,
) -> EventTarget =
  #| (self) => self

///|
pub extern "js" fn NetworkInformation::get_type(
  self : NetworkInformation,
) -> ConnectionType =
  #| (self) => ['bluetooth', 'cellular', 'ethernet', 'mixed', 'none', 'other', 'unknown', 'wifi', 'wimax'].indexOf(self.type)

///|
pub extern "js" fn NetworkInformation::get_effective_type(
  self : NetworkInformation,
) -> EffectiveConnectionType =
  #| (self) => ['2g', '3g', '4g', 'slow-2g'].indexOf(self.effectiveType)

///|
pub extern "js" fn NetworkInformation::get_downlink_max(
  self : NetworkInformation,
) -> Megabit =
  #| (self) => self.downlinkMax

///|
pub extern "js" fn NetworkInformation::get_downlink(
  self : NetworkInformation,
) -> Megabit =
  #| (self) => self.downlink

///|
pub extern "js" fn NetworkInformation::get_rtt(
  self : NetworkInformation,
) -> Millisecond =
  #| (self) => self.rtt

///|
pub extern "js" fn NetworkInformation::set_onchange(
  self : NetworkInformation,
  handler : (Event) -> Unit,
) -> Unit =
  #| (self, handler) => { self.onchange = (e) => handler(e) }

///|
pub extern "js" fn NetworkInformation::clear_onchange(
  self : NetworkInformation,
) -> Unit =
  #| (self) => { self.onchange = null }

///|
pub extern "js" fn NetworkInformation::get_save_data(
  self : NetworkInformation,
) -> Bool =
  #| (self) => self.saveData