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

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

glib::wrapper! {
    /// Indicates that the request succeeded.
    ///
    /// ## Properties
    ///
    ///
    /// #### `error-type`
    ///  Readable | Writeable
    ///
    ///
    /// #### `description`
    ///  Readable | Writeable
    ///
    /// # Implements
    ///
    /// [`ErrorExt`][trait@crate::prelude::ErrorExt], [`ResponseExt`][trait@crate::prelude::ResponseExt]
    #[doc(alias = "AstalGreetError")]
    pub struct Error(Object<ffi::AstalGreetError, ffi::AstalGreetErrorClass>) @extends Response;

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

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

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

// rustdoc-stripper-ignore-next
        /// A [builder-pattern] type to construct [`Error`] 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 ErrorBuilder {
            builder: glib::object::ObjectBuilder<'static, Error>,
        }

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

                            pub fn error_type(self, error_type: ErrorType) -> Self {
                            Self { builder: self.builder.property("error-type", error_type), }
                        }

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

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

/// Trait containing all [`struct@Error`] methods.
///
/// # Implementors
///
/// [`Error`][struct@crate::Error]
pub trait ErrorExt: IsA<Error> + 'static {
    #[doc(alias = "astal_greet_error_get_error_type")]
    #[doc(alias = "get_error_type")]
    fn error_type(&self) -> ErrorType {
        unsafe {
            from_glib(ffi::astal_greet_error_get_error_type(self.as_ref().to_glib_none().0))
        }
    }

    #[doc(alias = "astal_greet_error_get_description")]
    #[doc(alias = "get_description")]
    fn description(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::astal_greet_error_get_description(self.as_ref().to_glib_none().0))
        }
    }

    #[doc(alias = "error-type")]
    fn set_error_type(&self, error_type: ErrorType) {
        ObjectExt::set_property(self.as_ref(),"error-type", error_type)
    }

    fn set_description(&self, description: Option<&str>) {
        ObjectExt::set_property(self.as_ref(),"description", description)
    }

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

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

impl<O: IsA<Error>> ErrorExt for O {}
