// This file was generated by gir (https://github.com/gtk-rs/gir)
// from ../../girs
// from ../../gtk-girs
// DO NOT EDIT

use crate::{DeviceState, Internet, ffi, nm};
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    ///
    ///
    /// ## Properties
    ///
    ///
    /// #### `device`
    ///  Readable | Writeable | Construct
    ///
    ///
    /// #### `speed`
    ///  Readable | Writeable
    ///
    ///
    /// #### `internet`
    ///  Readable | Writeable
    ///
    ///
    /// #### `state`
    ///  Readable | Writeable
    ///
    ///
    /// #### `icon-name`
    ///  Readable | Writeable
    ///
    /// # Implements
    ///
    /// [`WiredExt`][trait@crate::prelude::WiredExt]
    #[doc(alias = "AstalNetworkWired")]
    pub struct Wired(Object<ffi::AstalNetworkWired, ffi::AstalNetworkWiredClass>);

    match fn {
        type_ => || ffi::astal_network_wired_get_type(),
    }
}

impl Wired {
    pub const NONE: Option<&'static Wired> = None;

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`Wired`] objects.
    ///
    /// This method returns an instance of [`WiredBuilder`](crate::builders::WiredBuilder) which can be used to create [`Wired`] objects.
    pub fn builder() -> WiredBuilder {
        WiredBuilder::new()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Wired`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct WiredBuilder {
    builder: glib::object::ObjectBuilder<'static, Wired>,
}

impl WiredBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    pub fn device(self, device: &impl IsA<nm::DeviceEthernet>) -> Self {
        Self {
            builder: self.builder.property("device", device.clone().upcast()),
        }
    }

    pub fn speed(self, speed: u32) -> Self {
        Self {
            builder: self.builder.property("speed", speed),
        }
    }

    pub fn internet(self, internet: Internet) -> Self {
        Self {
            builder: self.builder.property("internet", internet),
        }
    }

    pub fn state(self, state: DeviceState) -> Self {
        Self {
            builder: self.builder.property("state", state),
        }
    }

    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("icon-name", icon_name.into()),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`Wired`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> Wired {
        assert_initialized_main_thread!();
        self.builder.build()
    }
}

/// Trait containing all [`struct@Wired`] methods.
///
/// # Implementors
///
/// [`Wired`][struct@crate::Wired]
pub trait WiredExt: IsA<Wired> + 'static {
    #[doc(alias = "astal_network_wired_get_device")]
    #[doc(alias = "get_device")]
    fn device(&self) -> nm::DeviceEthernet {
        unsafe {
            from_glib_none(ffi::astal_network_wired_get_device(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "astal_network_wired_set_device")]
    fn set_device(&self, value: &impl IsA<nm::DeviceEthernet>) {
        unsafe {
            ffi::astal_network_wired_set_device(
                self.as_ref().to_glib_none().0,
                value.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "astal_network_wired_get_speed")]
    #[doc(alias = "get_speed")]
    fn speed(&self) -> u32 {
        unsafe { ffi::astal_network_wired_get_speed(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "astal_network_wired_get_internet")]
    #[doc(alias = "get_internet")]
    fn internet(&self) -> Internet {
        unsafe {
            from_glib(ffi::astal_network_wired_get_internet(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "astal_network_wired_get_state")]
    #[doc(alias = "get_state")]
    fn state(&self) -> DeviceState {
        unsafe {
            from_glib(ffi::astal_network_wired_get_state(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "astal_network_wired_get_icon_name")]
    #[doc(alias = "get_icon_name")]
    fn icon_name(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::astal_network_wired_get_icon_name(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_speed(&self, speed: u32) {
        ObjectExt::set_property(self.as_ref(), "speed", speed)
    }

    fn set_internet(&self, internet: Internet) {
        ObjectExt::set_property(self.as_ref(), "internet", internet)
    }

    fn set_state(&self, state: DeviceState) {
        ObjectExt::set_property(self.as_ref(), "state", state)
    }

    #[doc(alias = "icon-name")]
    fn set_icon_name(&self, icon_name: Option<&str>) {
        ObjectExt::set_property(self.as_ref(), "icon-name", icon_name)
    }

    #[doc(alias = "device")]
    fn connect_device_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_device_trampoline<P: IsA<Wired>, F: Fn(&P) + 'static>(
            this: *mut ffi::AstalNetworkWired,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Wired::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::device".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_device_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "speed")]
    fn connect_speed_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_speed_trampoline<P: IsA<Wired>, F: Fn(&P) + 'static>(
            this: *mut ffi::AstalNetworkWired,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Wired::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::speed".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_speed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "internet")]
    fn connect_internet_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_internet_trampoline<P: IsA<Wired>, F: Fn(&P) + 'static>(
            this: *mut ffi::AstalNetworkWired,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Wired::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::internet".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_internet_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "state")]
    fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_state_trampoline<P: IsA<Wired>, F: Fn(&P) + 'static>(
            this: *mut ffi::AstalNetworkWired,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Wired::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::state".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_state_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "icon-name")]
    fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_icon_name_trampoline<P: IsA<Wired>, F: Fn(&P) + 'static>(
            this: *mut ffi::AstalNetworkWired,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Wired::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::icon-name".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_icon_name_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<Wired>> WiredExt for O {}
