// GENERATED — DO NOT EDIT

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

///|
pub(open) trait IPermission {
  fn as_permission(Self) -> Permission
  fn acquire(Self, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn get_allowed(Self) -> Bool = _
  fn get_can_acquire(Self) -> Bool = _
  fn get_can_release(Self) -> Bool = _
  fn impl_update(Self, Bool, Bool, Bool) -> Unit = _
  fn release(Self, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn acquire_async(Self, &ICancellable?, (Result[Bool, @glib.Error_]) -> Unit) -> Unit = _
  fn release_async(Self, &ICancellable?, (Result[Bool, @glib.Error_]) -> Unit) -> Unit = _
}

///|
pub impl IPermission for Permission with fn as_permission(self) {
  self
}

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

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

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

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

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

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.Permission.impl_update.html).
#borrow(self)
pub extern "c" fn Permission::impl_update(
  self : Permission,
  allowed : Bool,
  can_acquire : Bool,
  can_release : Bool,
) = "moonbit_g_permission_impl_update"

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

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.Permission.release.html).
pub fn Permission::release(
  self : Permission,
  cancellable : &ICancellable?,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_permission_release(
    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_, cancellable)
extern "c" fn g_permission_acquire_async(
  self_ : Permission,
  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_permission_acquire_async"

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

///|
#borrow(self_, cancellable)
extern "c" fn g_permission_release_async(
  self_ : Permission,
  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_permission_release_async"

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

///|
impl IPermission with fn acquire(self, cancellable) -> Bool raise @glib.Error_ {
  self.as_permission().acquire(cancellable)
}

///|
impl IPermission with fn get_allowed(self) -> Bool {
  self.as_permission().get_allowed()
}

///|
impl IPermission with fn get_can_acquire(self) -> Bool {
  self.as_permission().get_can_acquire()
}

///|
impl IPermission with fn get_can_release(self) -> Bool {
  self.as_permission().get_can_release()
}

///|
impl IPermission with fn impl_update(self, allowed, can_acquire, can_release) -> Unit {
  self.as_permission().impl_update(allowed, can_acquire, can_release)
}

///|
impl IPermission with fn release(self, cancellable) -> Bool raise @glib.Error_ {
  self.as_permission().release(cancellable)
}

///|
impl IPermission with fn acquire_async(self, cancellable, callback) -> Unit {
  self.as_permission().acquire_async(cancellable, callback)
}

///|
impl IPermission with fn release_async(self, cancellable, callback) -> Unit {
  self.as_permission().release_async(cancellable, callback)
}

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

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