// GENERATED — DO NOT EDIT

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

///|
pub(open) trait ISocketAddressEnumerator {
  fn as_socket_address_enumerator(Self) -> SocketAddressEnumerator
  fn next(Self, &ICancellable?) -> SocketAddress? raise @glib.Error_ = _
  fn next_async(
    Self,
    &ICancellable?,
    (Result[SocketAddress?, @glib.Error_]) -> Unit,
  ) -> Unit = _
}

///|
pub impl ISocketAddressEnumerator for SocketAddressEnumerator with fn as_socket_address_enumerator(
  self,
) {
  self
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_socket_address_enumerator_next(
  self_ : SocketAddressEnumerator,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> @glib.Nullable[SocketAddress] = "moonbit_g_socket_address_enumerator_next"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.SocketAddressEnumerator.next.html).
pub fn SocketAddressEnumerator::next(
  self : SocketAddressEnumerator,
  cancellable : &ICancellable?,
) -> SocketAddress? raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let raw_result = moonbit_g_socket_address_enumerator_next(
    self,
    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 => ()
  }
  let result = raw_result.to_option()
  result
}

///|
#borrow(self_, cancellable)
extern "c" fn g_socket_address_enumerator_next_async(
  self_ : SocketAddressEnumerator,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      @glib.Nullable[SocketAddress],
      @glib.Nullable[@glib.Error_],
      (@glib.Nullable[SocketAddress], @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (@glib.Nullable[SocketAddress], @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_socket_address_enumerator_next_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.SocketAddressEnumerator.next_async.html).
pub fn SocketAddressEnumerator::next_async(
  self : SocketAddressEnumerator,
  cancellable : &ICancellable?,
  callback : (Result[SocketAddress?, @glib.Error_]) -> Unit,
) -> Unit {
  g_socket_address_enumerator_next_async(
    self,
    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(Some(v)))
            None => callback(Ok(None))
          }
      }
    },
  )
}

///|
impl ISocketAddressEnumerator with fn next(self, cancellable) -> SocketAddress? raise @glib.Error_ {
  self.as_socket_address_enumerator().next(cancellable)
}

///|
impl ISocketAddressEnumerator with fn next_async(self, cancellable, callback) -> Unit {
  self.as_socket_address_enumerator().next_async(cancellable, callback)
}

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

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