// GENERATED — DO NOT EDIT

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

///|
pub(open) trait IFileEnumerator {
  fn as_file_enumerator(Self) -> FileEnumerator
  fn close(Self, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn get_child(Self, &IFileInfo) -> File = _
  fn get_container(Self) -> File = _
  fn has_pending(Self) -> Bool = _
  fn is_closed(Self) -> Bool = _
  fn next_file(Self, &ICancellable?) -> FileInfo? raise @glib.Error_ = _
  fn next_files_finish(Self, &IAsyncResult) -> Array[FileInfo] raise @glib.Error_ = _
  fn set_pending(Self, Bool) -> Unit = _
  fn close_async(
    Self,
    Int,
    &ICancellable?,
    (Result[Bool, @glib.Error_]) -> Unit,
  ) -> Unit = _
}

///|
pub impl IFileEnumerator for FileEnumerator with fn as_file_enumerator(self) {
  self
}

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

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

///|
#borrow(self_, info)
extern "c" fn moonbit_g_file_enumerator_get_child(
  self_ : FileEnumerator,
  info : FileInfo,
) -> File = "moonbit_g_file_enumerator_get_child"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileEnumerator.get_child.html).
pub fn FileEnumerator::get_child(
  self : FileEnumerator,
  info : &IFileInfo,
) -> File {
  moonbit_g_file_enumerator_get_child(self, info.as_file_info())
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileEnumerator.get_container.html).
#borrow(self)
pub extern "c" fn FileEnumerator::get_container(self : FileEnumerator) -> File = "moonbit_g_file_enumerator_get_container"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileEnumerator.has_pending.html).
#borrow(self)
pub extern "c" fn FileEnumerator::has_pending(self : FileEnumerator) -> Bool = "moonbit_g_file_enumerator_has_pending"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileEnumerator.is_closed.html).
#borrow(self)
pub extern "c" fn FileEnumerator::is_closed(self : FileEnumerator) -> Bool = "moonbit_g_file_enumerator_is_closed"

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

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileEnumerator.next_file.html).
pub fn FileEnumerator::next_file(
  self : FileEnumerator,
  cancellable : &ICancellable?,
) -> FileInfo? raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let raw_result = moonbit_g_file_enumerator_next_file(
    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_, result, error, result_2)
extern "c" fn moonbit_g_file_enumerator_next_files_finish(
  self_ : FileEnumerator,
  result : AsyncResult,
  error : Ref[@glib.Nullable[@glib.Error_]],
  result_2 : Ref[FixedArray[FileInfo]],
) = "moonbit_g_file_enumerator_next_files_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileEnumerator.next_files_finish.html).
pub fn FileEnumerator::next_files_finish(
  self : FileEnumerator,
  result : &IAsyncResult,
) -> Array[FileInfo] raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result_ref : Ref[FixedArray[FileInfo]] = Ref([])
  moonbit_g_file_enumerator_next_files_finish(
    self,
    result.as_async_result(),
    error_,
    result_ref,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  let values : Array[FileInfo] = Array::new(capacity=result_ref.val.length())
  for value in result_ref.val {
    values.push(value)
  }
  values
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileEnumerator.set_pending.html).
#borrow(self)
pub extern "c" fn FileEnumerator::set_pending(
  self : FileEnumerator,
  pending : Bool,
) = "moonbit_g_file_enumerator_set_pending"

///|
#borrow(self_, cancellable)
extern "c" fn g_file_enumerator_close_async(
  self_ : FileEnumerator,
  io_priority : Int,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      Bool,
      @glib.Nullable[@glib.Error_],
      (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_file_enumerator_close_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileEnumerator.close_async.html).
pub fn FileEnumerator::close_async(
  self : FileEnumerator,
  io_priority : Int,
  cancellable : &ICancellable?,
  callback : (Result[Bool, @glib.Error_]) -> Unit,
) -> Unit {
  g_file_enumerator_close_async(
    self,
    io_priority,
    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 => callback(Ok(result))
      }
    },
  )
}

///|
impl IFileEnumerator with fn close(self, cancellable) -> Bool raise @glib.Error_ {
  self.as_file_enumerator().close(cancellable)
}

///|
impl IFileEnumerator with fn get_child(self, info) -> File {
  self.as_file_enumerator().get_child(info)
}

///|
impl IFileEnumerator with fn get_container(self) -> File {
  self.as_file_enumerator().get_container()
}

///|
impl IFileEnumerator with fn has_pending(self) -> Bool {
  self.as_file_enumerator().has_pending()
}

///|
impl IFileEnumerator with fn is_closed(self) -> Bool {
  self.as_file_enumerator().is_closed()
}

///|
impl IFileEnumerator with fn next_file(self, cancellable) -> FileInfo? raise @glib.Error_ {
  self.as_file_enumerator().next_file(cancellable)
}

///|
impl IFileEnumerator with fn next_files_finish(self, result) -> Array[FileInfo] raise @glib.Error_ {
  self.as_file_enumerator().next_files_finish(result)
}

///|
impl IFileEnumerator with fn set_pending(self, pending) -> Unit {
  self.as_file_enumerator().set_pending(pending)
}

///|
impl IFileEnumerator with fn close_async(
  self,
  io_priority,
  cancellable,
  callback,
) -> Unit {
  self.as_file_enumerator().close_async(io_priority, cancellable, callback)
}

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

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