// GENERATED — DO NOT EDIT

///|
/// [Upstream documentation](https://docs.gtk.org/gio/class.DBusProxy.html).
pub type DBusProxy

///|
pub(open) trait IDBusProxy {
  fn as_dbus_proxy(Self) -> DBusProxy
  fn call_sync(
    Self,
    String,
    &@glib.IVariant?,
    DBusCallFlags,
    Int,
    &ICancellable?,
  ) -> @glib.Variant raise @glib.Error_ = _
  fn get_cached_property(Self, String) -> @glib.Variant? = _
  fn get_connection(Self) -> DBusConnection = _
  fn get_default_timeout(Self) -> Int = _
  fn get_flags(Self) -> DBusProxyFlags = _
  fn get_interface_name(Self) -> String = _
  fn get_name(Self) -> String? = _
  fn get_name_owner(Self) -> String? = _
  fn get_object_path(Self) -> String = _
  fn set_cached_property(Self, String, &@glib.IVariant?) -> Unit = _
  fn set_default_timeout(Self, Int) -> Unit = _
  fn call(
    Self,
    String,
    &@glib.IVariant?,
    DBusCallFlags,
    Int,
    &ICancellable?,
    (Result[@glib.Variant, @glib.Error_]) -> Unit,
  ) -> Unit = _
}

///|
pub impl IDBusProxy for DBusProxy with fn as_dbus_proxy(self) {
  self
}

///|
/// Implementation contract for DBusProxy.g_properties_changed. Self is the retained MoonBit state; the second parameter is the invoked DBusProxy object.
pub(open) trait VDBusProxyGPropertiesChanged {
  fn g_properties_changed(Self, DBusProxy, &@glib.IVariant, String) -> Unit
}

///|
/// Implementation contract for DBusProxy.g_signal. Self is the retained MoonBit state; the second parameter is the invoked DBusProxy object.
pub(open) trait VDBusProxyGSignal {
  fn g_signal(Self, DBusProxy, String, String, &@glib.IVariant) -> Unit
}

///|
#borrow(res, error)
extern "c" fn moonbit_g_dbus_proxy_new_finish(
  res : AsyncResult,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> DBusProxy = "moonbit_g_dbus_proxy_new_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/ctor.DBusProxy.new_finish.html).
pub fn DBusProxy::new_finish(
  res : &IAsyncResult,
) -> DBusProxy raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_proxy_new_finish(res.as_async_result(), error_)
  match error_.val.to_option() {
    Some(e) => raise e
    None => result
  }
}

///|
#borrow(res, error)
extern "c" fn moonbit_g_dbus_proxy_new_for_bus_finish(
  res : AsyncResult,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> DBusProxy = "moonbit_g_dbus_proxy_new_for_bus_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/ctor.DBusProxy.new_for_bus_finish.html).
pub fn DBusProxy::new_for_bus_finish(
  res : &IAsyncResult,
) -> DBusProxy raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_proxy_new_for_bus_finish(
    res.as_async_result(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => result
  }
}

///|
#borrow(self_, method_name, parameters, cancellable, error)
extern "c" fn moonbit_g_dbus_proxy_call_sync(
  self_ : DBusProxy,
  method_name : Bytes,
  parameters : @glib.Nullable[@glib.Variant],
  flags : Int,
  timeout_msec : Int,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> @glib.Variant = "moonbit_g_dbus_proxy_call_sync"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.call_sync.html).
pub fn DBusProxy::call_sync(
  self : DBusProxy,
  method_name : String,
  parameters : &@glib.IVariant?,
  flags : DBusCallFlags,
  timeout_msec : Int,
  cancellable : &ICancellable?,
) -> @glib.Variant raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_proxy_call_sync(
    self,
    @encoding/utf8.encode(method_name),
    match parameters {
      Some(v) => @glib.Nullable::some(v.as_variant())
      None => @glib.Nullable::null()
    },
    flags.to_int(),
    timeout_msec,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, property_name)
extern "c" fn moonbit_g_dbus_proxy_get_cached_property(
  self_ : DBusProxy,
  property_name : Bytes,
) -> @glib.Nullable[@glib.Variant] = "moonbit_g_dbus_proxy_get_cached_property"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.get_cached_property.html).
pub fn DBusProxy::get_cached_property(
  self : DBusProxy,
  property_name : String,
) -> @glib.Variant? {
  let raw_result = moonbit_g_dbus_proxy_get_cached_property(
    self,
    @encoding/utf8.encode(property_name),
  )
  raw_result.to_option()
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.get_connection.html).
#borrow(self)
pub extern "c" fn DBusProxy::get_connection(self : DBusProxy) -> DBusConnection = "moonbit_g_dbus_proxy_get_connection"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.get_default_timeout.html).
#borrow(self)
pub extern "c" fn DBusProxy::get_default_timeout(self : DBusProxy) -> Int = "moonbit_g_dbus_proxy_get_default_timeout"

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_proxy_get_flags(self_ : DBusProxy) -> Int = "moonbit_g_dbus_proxy_get_flags"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.get_flags.html).
pub fn DBusProxy::get_flags(self : DBusProxy) -> DBusProxyFlags {
  DBusProxyFlags::from_int(moonbit_g_dbus_proxy_get_flags(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_proxy_get_interface_name(
  self_ : DBusProxy,
) -> Bytes = "moonbit_g_dbus_proxy_get_interface_name"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.get_interface_name.html).
pub fn DBusProxy::get_interface_name(self : DBusProxy) -> String {
  @encoding/utf8.decode_lossy(moonbit_g_dbus_proxy_get_interface_name(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_proxy_get_name(
  self_ : DBusProxy,
) -> @glib.Nullable[Bytes] = "moonbit_g_dbus_proxy_get_name"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.get_name.html).
pub fn DBusProxy::get_name(self : DBusProxy) -> String? {
  let result = moonbit_g_dbus_proxy_get_name(self)
  match result.to_option() {
    Some(bytes) => Some(@encoding/utf8.decode_lossy(bytes))
    None => None
  }
}

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_proxy_get_name_owner(
  self_ : DBusProxy,
) -> @glib.Nullable[Bytes] = "moonbit_g_dbus_proxy_get_name_owner"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.get_name_owner.html).
pub fn DBusProxy::get_name_owner(self : DBusProxy) -> String? {
  let result = moonbit_g_dbus_proxy_get_name_owner(self)
  match result.to_option() {
    Some(bytes) => Some(@encoding/utf8.decode_lossy(bytes))
    None => None
  }
}

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_proxy_get_object_path(self_ : DBusProxy) -> Bytes = "moonbit_g_dbus_proxy_get_object_path"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.get_object_path.html).
pub fn DBusProxy::get_object_path(self : DBusProxy) -> String {
  @encoding/utf8.decode_lossy(moonbit_g_dbus_proxy_get_object_path(self))
}

///|
#borrow(self_, property_name, value)
extern "c" fn moonbit_g_dbus_proxy_set_cached_property(
  self_ : DBusProxy,
  property_name : Bytes,
  value : @glib.Nullable[@glib.Variant],
) = "moonbit_g_dbus_proxy_set_cached_property"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.set_cached_property.html).
pub fn DBusProxy::set_cached_property(
  self : DBusProxy,
  property_name : String,
  value : &@glib.IVariant?,
) -> Unit {
  moonbit_g_dbus_proxy_set_cached_property(
    self,
    @encoding/utf8.encode(property_name),
    match value {
      Some(v) => @glib.Nullable::some(v.as_variant())
      None => @glib.Nullable::null()
    },
  )
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.set_default_timeout.html).
#borrow(self)
pub extern "c" fn DBusProxy::set_default_timeout(
  self : DBusProxy,
  timeout_msec : Int,
) = "moonbit_g_dbus_proxy_set_default_timeout"

///|
#borrow(self_, method_name, parameters, cancellable)
extern "c" fn g_dbus_proxy_call(
  self_ : DBusProxy,
  method_name : Bytes,
  parameters : @glib.Nullable[@glib.Variant],
  flags : Int,
  timeout_msec : Int,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      @glib.Nullable[@glib.Variant],
      @glib.Nullable[@glib.Error_],
      (@glib.Nullable[@glib.Variant], @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (@glib.Nullable[@glib.Variant], @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_dbus_proxy_call"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusProxy.call.html).
pub fn DBusProxy::call(
  self : DBusProxy,
  method_name : String,
  parameters : &@glib.IVariant?,
  flags : DBusCallFlags,
  timeout_msec : Int,
  cancellable : &ICancellable?,
  callback : (Result[@glib.Variant, @glib.Error_]) -> Unit,
) -> Unit {
  g_dbus_proxy_call(
    self,
    @encoding/utf8.encode(method_name),
    match parameters {
      Some(v) => @glib.Nullable::some(v.as_variant())
      None => @glib.Nullable::null()
    },
    flags.to_int(),
    timeout_msec,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    fn(result, error, f) { f(result, error) },
    fn(result, error) {
      match error.to_option() {
        Some(e) => callback(Err(e))
        None =>
          match result.to_option() {
            Some(v) => callback(Ok(v))
            None => ()
          }
      }
    },
  )
}

///|
#borrow(self_)
extern "c" fn moonbit_gd_bus_proxy_get_g_connection(
  self_ : DBusProxy,
) -> @glib.Nullable[DBusConnection] = "moonbit_gd_bus_proxy_get_g_connection"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusProxy.g-connection.html).
pub fn DBusProxy::get_g_connection(self : DBusProxy) -> DBusConnection? {
  moonbit_gd_bus_proxy_get_g_connection(self).to_option()
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusProxy.g-default-timeout.html).
#borrow(self_)
pub extern "c" fn DBusProxy::get_g_default_timeout(self_ : DBusProxy) -> Int = "moonbit_gd_bus_proxy_get_g_default_timeout"

///|
#borrow(self_, value)
pub extern "c" fn DBusProxy::set_g_default_timeout(
  self_ : DBusProxy,
  value : Int,
) = "moonbit_gd_bus_proxy_set_g_default_timeout"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusProxy.g-flags.html).
#borrow(self_)
extern "c" fn __ffi_moonbit_gd_bus_proxy_get_g_flags(self_ : DBusProxy) -> Int = "moonbit_gd_bus_proxy_get_g_flags"

///|
pub fn DBusProxy::get_g_flags(self : DBusProxy) -> DBusProxyFlags {
  DBusProxyFlags::from_int(__ffi_moonbit_gd_bus_proxy_get_g_flags(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_gd_bus_proxy_get_g_interface_name(
  self_ : DBusProxy,
) -> Bytes = "moonbit_gd_bus_proxy_get_g_interface_name"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusProxy.g-interface-name.html).
pub fn DBusProxy::get_g_interface_name(self : DBusProxy) -> String {
  @encoding/utf8.decode_lossy(moonbit_gd_bus_proxy_get_g_interface_name(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_gd_bus_proxy_get_g_name(self_ : DBusProxy) -> Bytes = "moonbit_gd_bus_proxy_get_g_name"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusProxy.g-name.html).
pub fn DBusProxy::get_g_name(self : DBusProxy) -> String {
  @encoding/utf8.decode_lossy(moonbit_gd_bus_proxy_get_g_name(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_gd_bus_proxy_get_g_name_owner(self_ : DBusProxy) -> Bytes = "moonbit_gd_bus_proxy_get_g_name_owner"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusProxy.g-name-owner.html).
pub fn DBusProxy::get_g_name_owner(self : DBusProxy) -> String {
  @encoding/utf8.decode_lossy(moonbit_gd_bus_proxy_get_g_name_owner(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_gd_bus_proxy_get_g_object_path(
  self_ : DBusProxy,
) -> Bytes = "moonbit_gd_bus_proxy_get_g_object_path"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusProxy.g-object-path.html).
pub fn DBusProxy::get_g_object_path(self : DBusProxy) -> String {
  @encoding/utf8.decode_lossy(moonbit_gd_bus_proxy_get_g_object_path(self))
}

///|
impl IDBusProxy with fn call_sync(
  self,
  method_name,
  parameters,
  flags,
  timeout_msec,
  cancellable,
) -> @glib.Variant raise @glib.Error_ {
  self
  .as_dbus_proxy()
  .call_sync(method_name, parameters, flags, timeout_msec, cancellable)
}

///|
impl IDBusProxy with fn get_cached_property(self, property_name) -> @glib.Variant? {
  self.as_dbus_proxy().get_cached_property(property_name)
}

///|
impl IDBusProxy with fn get_connection(self) -> DBusConnection {
  self.as_dbus_proxy().get_connection()
}

///|
impl IDBusProxy with fn get_default_timeout(self) -> Int {
  self.as_dbus_proxy().get_default_timeout()
}

///|
impl IDBusProxy with fn get_flags(self) -> DBusProxyFlags {
  self.as_dbus_proxy().get_flags()
}

///|
impl IDBusProxy with fn get_interface_name(self) -> String {
  self.as_dbus_proxy().get_interface_name()
}

///|
impl IDBusProxy with fn get_name(self) -> String? {
  self.as_dbus_proxy().get_name()
}

///|
impl IDBusProxy with fn get_name_owner(self) -> String? {
  self.as_dbus_proxy().get_name_owner()
}

///|
impl IDBusProxy with fn get_object_path(self) -> String {
  self.as_dbus_proxy().get_object_path()
}

///|
impl IDBusProxy with fn set_cached_property(self, property_name, value) -> Unit {
  self.as_dbus_proxy().set_cached_property(property_name, value)
}

///|
impl IDBusProxy with fn set_default_timeout(self, timeout_msec) -> Unit {
  self.as_dbus_proxy().set_default_timeout(timeout_msec)
}

///|
impl IDBusProxy with fn call(
  self,
  method_name,
  parameters,
  flags,
  timeout_msec,
  cancellable,
  callback,
) -> Unit {
  self
  .as_dbus_proxy()
  .call(method_name, parameters, flags, timeout_msec, cancellable, callback)
}

///|
pub fn DBusProxy::as_gobject_object(self : DBusProxy) -> @gobject.Object = "%identity"

///|
pub impl @gobject.IObject for DBusProxy with fn as_object(self) {
  self.as_gobject_object()
}

///|
pub fn DBusProxy::as_async_initable(self : DBusProxy) -> AsyncInitable = "%identity"

///|
pub impl IAsyncInitable for DBusProxy with fn as_async_initable(self) {
  self.as_async_initable()
}

///|
pub fn DBusProxy::as_dbus_interface(self : DBusProxy) -> DBusInterface = "%identity"

///|
pub impl IDBusInterface for DBusProxy with fn as_dbus_interface(self) {
  self.as_dbus_interface()
}

///|
pub fn DBusProxy::as_initable(self : DBusProxy) -> Initable = "%identity"

///|
pub impl IInitable for DBusProxy with fn as_initable(self) {
  self.as_initable()
}