// GENERATED — DO NOT EDIT

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

///|
pub(open) trait IFileOutputStream {
  fn as_file_output_stream(Self) -> FileOutputStream
  fn get_etag(Self) -> String? = _
  fn query_info(Self, String, &ICancellable?) -> FileInfo raise @glib.Error_ = _
  fn query_info_async(
    Self,
    String,
    Int,
    &ICancellable?,
    (Result[FileInfo, @glib.Error_]) -> Unit,
  ) -> Unit = _
}

///|
pub impl IFileOutputStream for FileOutputStream with fn as_file_output_stream(
  self,
) {
  self
}

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

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

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

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileOutputStream.query_info.html).
pub fn FileOutputStream::query_info(
  self : FileOutputStream,
  attributes : String,
  cancellable : &ICancellable?,
) -> FileInfo raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_file_output_stream_query_info(
    self,
    @encoding/utf8.encode(attributes),
    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_, attributes, cancellable)
extern "c" fn g_file_output_stream_query_info_async(
  self_ : FileOutputStream,
  attributes : Bytes,
  io_priority : Int,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      @glib.Nullable[FileInfo],
      @glib.Nullable[@glib.Error_],
      (@glib.Nullable[FileInfo], @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (@glib.Nullable[FileInfo], @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_file_output_stream_query_info_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.FileOutputStream.query_info_async.html).
pub fn FileOutputStream::query_info_async(
  self : FileOutputStream,
  attributes : String,
  io_priority : Int,
  cancellable : &ICancellable?,
  callback : (Result[FileInfo, @glib.Error_]) -> Unit,
) -> Unit {
  g_file_output_stream_query_info_async(
    self,
    @encoding/utf8.encode(attributes),
    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 =>
          match result.to_option() {
            Some(v) => callback(Ok(v))
            None => ()
          }
      }
    },
  )
}

///|
impl IFileOutputStream with fn get_etag(self) -> String? {
  self.as_file_output_stream().get_etag()
}

///|
impl IFileOutputStream with fn query_info(self, attributes, cancellable) -> FileInfo raise @glib.Error_ {
  self.as_file_output_stream().query_info(attributes, cancellable)
}

///|
impl IFileOutputStream with fn query_info_async(
  self,
  attributes,
  io_priority,
  cancellable,
  callback,
) -> Unit {
  self
  .as_file_output_stream()
  .query_info_async(attributes, io_priority, cancellable, callback)
}

///|
pub fn FileOutputStream::as_output_stream(
  self : FileOutputStream,
) -> OutputStream = "%identity"

///|
pub impl IOutputStream for FileOutputStream with fn as_output_stream(self) {
  self.as_output_stream()
}

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

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

///|
pub fn FileOutputStream::as_seekable(self : FileOutputStream) -> Seekable = "%identity"

///|
pub impl ISeekable for FileOutputStream with fn as_seekable(self) {
  self.as_seekable()
}