// GENERATED — DO NOT EDIT

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

///|
pub(open) trait IProxy {
  fn as_proxy(Self) -> Proxy
  fn connect(Self, &IIOStream, &IProxyAddress, &ICancellable?) -> IOStream raise @glib.Error_ = _
  fn supports_hostname(Self) -> Bool = _
  fn connect_async(
    Self,
    &IIOStream,
    &IProxyAddress,
    &ICancellable?,
    (Result[IOStream, @glib.Error_]) -> Unit,
  ) -> Unit = _
}

///|
pub impl IProxy for Proxy with fn as_proxy(self) {
  self
}

///|
#borrow(protocol)
extern "c" fn moonbit_g_proxy_get_default_for_protocol(
  protocol : Bytes,
) -> @glib.Nullable[Proxy] = "moonbit_g_proxy_get_default_for_protocol"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/type_func.Proxy.get_default_for_protocol.html).
pub fn Proxy::get_default_for_protocol(protocol : String) -> Proxy? {
  let raw_result = moonbit_g_proxy_get_default_for_protocol(
    @encoding/utf8.encode(protocol),
  )
  raw_result.to_option()
}

///|
#borrow(self_, connection, proxy_address, cancellable, error)
extern "c" fn moonbit_g_proxy_connect(
  self_ : Proxy,
  connection : IOStream,
  proxy_address : ProxyAddress,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> IOStream = "moonbit_g_proxy_connect"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.Proxy.connect.html).
pub fn Proxy::connect(
  self : Proxy,
  connection : &IIOStream,
  proxy_address : &IProxyAddress,
  cancellable : &ICancellable?,
) -> IOStream raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_proxy_connect(
    self,
    connection.as_io_stream(),
    proxy_address.as_proxy_address(),
    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.Proxy.supports_hostname.html).
#borrow(self)
pub extern "c" fn Proxy::supports_hostname(self : Proxy) -> Bool = "moonbit_g_proxy_supports_hostname"

///|
#borrow(self_, connection, proxy_address, cancellable)
extern "c" fn g_proxy_connect_async(
  self_ : Proxy,
  connection : IOStream,
  proxy_address : ProxyAddress,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      @glib.Nullable[IOStream],
      @glib.Nullable[@glib.Error_],
      (@glib.Nullable[IOStream], @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (@glib.Nullable[IOStream], @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_proxy_connect_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.Proxy.connect_async.html).
pub fn Proxy::connect_async(
  self : Proxy,
  connection : &IIOStream,
  proxy_address : &IProxyAddress,
  cancellable : &ICancellable?,
  callback : (Result[IOStream, @glib.Error_]) -> Unit,
) -> Unit {
  g_proxy_connect_async(
    self,
    connection.as_io_stream(),
    proxy_address.as_proxy_address(),
    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 IProxy with fn connect(self, connection, proxy_address, cancellable) -> IOStream raise @glib.Error_ {
  self.as_proxy().connect(connection, proxy_address, cancellable)
}

///|
impl IProxy with fn supports_hostname(self) -> Bool {
  self.as_proxy().supports_hostname()
}

///|
impl IProxy with fn connect_async(
  self,
  connection,
  proxy_address,
  cancellable,
  callback,
) -> Unit {
  self
  .as_proxy()
  .connect_async(connection, proxy_address, cancellable, callback)
}