// This file was autogenerated by some hot garbage in the `uniffi` crate.
// Trust me, you don't want to mess with it!

// swiftlint:disable all
import Foundation

// Depending on the consumer's build setup, the low-level FFI code
// might be in a separate module, or it might be compiled inline into
// this module. This is a bit of light hackery to work with both.
#if canImport(nym_vpn_rpc_uniffiFFI)
import nym_vpn_rpc_uniffiFFI
#endif

fileprivate extension RustBuffer {
    // Allocate a new buffer, copying the contents of a `UInt8` array.
    init(bytes: [UInt8]) {
        let rbuf = bytes.withUnsafeBufferPointer { ptr in
            RustBuffer.from(ptr)
        }
        self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
    }

    static func empty() -> RustBuffer {
        RustBuffer(capacity: 0, len:0, data: nil)
    }

    static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
        try! rustCall { ffi_nym_vpn_rpc_uniffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
    }

    // Frees the buffer in place.
    // The buffer must not be used after this is called.
    func deallocate() {
        try! rustCall { ffi_nym_vpn_rpc_uniffi_rustbuffer_free(self, $0) }
    }
}

fileprivate extension ForeignBytes {
    init(bufferPointer: UnsafeBufferPointer<UInt8>) {
        self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
    }
}

// For every type used in the interface, we provide helper methods for conveniently
// lifting and lowering that type from C-compatible data, and for reading and writing
// values of that type in a buffer.

// Helper classes/extensions that don't change.
// Someday, this will be in a library of its own.

fileprivate extension Data {
    init(rustBuffer: RustBuffer) {
        self.init(
            bytesNoCopy: rustBuffer.data!,
            count: Int(rustBuffer.len),
            deallocator: .none
        )
    }
}

// Define reader functionality.  Normally this would be defined in a class or
// struct, but we use standalone functions instead in order to make external
// types work.
//
// With external types, one swift source file needs to be able to call the read
// method on another source file's FfiConverter, but then what visibility
// should Reader have?
// - If Reader is fileprivate, then this means the read() must also
//   be fileprivate, which doesn't work with external types.
// - If Reader is internal/public, we'll get compile errors since both source
//   files will try define the same type.
//
// Instead, the read() method and these helper functions input a tuple of data

fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
    (data: data, offset: 0)
}

// Reads an integer at the current offset, in big-endian order, and advances
// the offset on success. Throws if reading the integer would move the
// offset past the end of the buffer.
fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
    let range = reader.offset..<reader.offset + MemoryLayout<T>.size
    guard reader.data.count >= range.upperBound else {
        throw UniffiInternalError.bufferOverflow
    }
    if T.self == UInt8.self {
        let value = reader.data[reader.offset]
        reader.offset += 1
        return value as! T
    }
    var value: T = 0
    let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
    reader.offset = range.upperBound
    return value.bigEndian
}

// Reads an arbitrary number of bytes, to be used to read
// raw bytes, this is useful when lifting strings
fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
    let range = reader.offset..<(reader.offset+count)
    guard reader.data.count >= range.upperBound else {
        throw UniffiInternalError.bufferOverflow
    }
    var value = [UInt8](repeating: 0, count: count)
    value.withUnsafeMutableBufferPointer({ buffer in
        reader.data.copyBytes(to: buffer, from: range)
    })
    reader.offset = range.upperBound
    return value
}

// Reads a float at the current offset.
fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
    return Float(bitPattern: try readInt(&reader))
}

// Reads a float at the current offset.
fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
    return Double(bitPattern: try readInt(&reader))
}

// Indicates if the offset has reached the end of the buffer.
fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
    return reader.offset < reader.data.count
}

// Define writer functionality.  Normally this would be defined in a class or
// struct, but we use standalone functions instead in order to make external
// types work.  See the above discussion on Readers for details.

fileprivate func createWriter() -> [UInt8] {
    return []
}

fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
    writer.append(contentsOf: byteArr)
}

// Writes an integer in big-endian order.
//
// Warning: make sure what you are trying to write
// is in the correct type!
fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
    var value = value.bigEndian
    withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
}

fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
    writeInt(&writer, value.bitPattern)
}

fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
    writeInt(&writer, value.bitPattern)
}

// Protocol for types that transfer other types across the FFI. This is
// analogous to the Rust trait of the same name.
fileprivate protocol FfiConverter {
    associatedtype FfiType
    associatedtype SwiftType

    static func lift(_ value: FfiType) throws -> SwiftType
    static func lower(_ value: SwiftType) -> FfiType
    static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
    static func write(_ value: SwiftType, into buf: inout [UInt8])
}

// Types conforming to `Primitive` pass themselves directly over the FFI.
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }

extension FfiConverterPrimitive {
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public static func lift(_ value: FfiType) throws -> SwiftType {
        return value
    }

#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public static func lower(_ value: SwiftType) -> FfiType {
        return value
    }
}

// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
// Used for complex types where it's hard to write a custom lift/lower.
fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}

extension FfiConverterRustBuffer {
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public static func lift(_ buf: RustBuffer) throws -> SwiftType {
        var reader = createReader(data: Data(rustBuffer: buf))
        let value = try read(from: &reader)
        if hasRemaining(reader) {
            throw UniffiInternalError.incompleteData
        }
        buf.deallocate()
        return value
    }

#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public static func lower(_ value: SwiftType) -> RustBuffer {
          var writer = createWriter()
          write(value, into: &writer)
          return RustBuffer(bytes: writer)
    }
}
// An error type for FFI errors. These errors occur at the UniFFI level, not
// the library level.
fileprivate enum UniffiInternalError: LocalizedError {
    case bufferOverflow
    case incompleteData
    case unexpectedOptionalTag
    case unexpectedEnumCase
    case unexpectedNullPointer
    case unexpectedRustCallStatusCode
    case unexpectedRustCallError
    case unexpectedStaleHandle
    case rustPanic(_ message: String)

    public var errorDescription: String? {
        switch self {
        case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
        case .incompleteData: return "The buffer still has data after lifting its containing value"
        case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
        case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
        case .unexpectedNullPointer: return "Raw pointer value was null"
        case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
        case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
        case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
        case let .rustPanic(message): return message
        }
    }
}

fileprivate extension NSLock {
    func withLock<T>(f: () throws -> T) rethrows -> T {
        self.lock()
        defer { self.unlock() }
        return try f()
    }
}

fileprivate let CALL_SUCCESS: Int8 = 0
fileprivate let CALL_ERROR: Int8 = 1
fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
fileprivate let CALL_CANCELLED: Int8 = 3

fileprivate extension RustCallStatus {
    init() {
        self.init(
            code: CALL_SUCCESS,
            errorBuf: RustBuffer.init(
                capacity: 0,
                len: 0,
                data: nil
            )
        )
    }
}

private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
    let neverThrow: ((RustBuffer) throws -> Never)? = nil
    return try makeRustCall(callback, errorHandler: neverThrow)
}

private func rustCallWithError<T, E: Swift.Error>(
    _ errorHandler: @escaping (RustBuffer) throws -> E,
    _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
    try makeRustCall(callback, errorHandler: errorHandler)
}

private func makeRustCall<T, E: Swift.Error>(
    _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
    errorHandler: ((RustBuffer) throws -> E)?
) throws -> T {
    uniffiEnsureNymVpnRpcUniffiInitialized()
    var callStatus = RustCallStatus.init()
    let returnedVal = callback(&callStatus)
    try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
    return returnedVal
}

private func uniffiCheckCallStatus<E: Swift.Error>(
    callStatus: RustCallStatus,
    errorHandler: ((RustBuffer) throws -> E)?
) throws {
    switch callStatus.code {
        case CALL_SUCCESS:
            return

        case CALL_ERROR:
            if let errorHandler = errorHandler {
                throw try errorHandler(callStatus.errorBuf)
            } else {
                callStatus.errorBuf.deallocate()
                throw UniffiInternalError.unexpectedRustCallError
            }

        case CALL_UNEXPECTED_ERROR:
            // When the rust code sees a panic, it tries to construct a RustBuffer
            // with the message.  But if that code panics, then it just sends back
            // an empty buffer.
            if callStatus.errorBuf.len > 0 {
                throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
            } else {
                callStatus.errorBuf.deallocate()
                throw UniffiInternalError.rustPanic("Rust panic")
            }

        case CALL_CANCELLED:
            fatalError("Cancellation not supported yet")

        default:
            throw UniffiInternalError.unexpectedRustCallStatusCode
    }
}

private func uniffiTraitInterfaceCall<T>(
    callStatus: UnsafeMutablePointer<RustCallStatus>,
    makeCall: () throws -> T,
    writeReturn: (T) -> ()
) {
    do {
        try writeReturn(makeCall())
    } catch let error {
        callStatus.pointee.code = CALL_UNEXPECTED_ERROR
        callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
    }
}

private func uniffiTraitInterfaceCallWithError<T, E>(
    callStatus: UnsafeMutablePointer<RustCallStatus>,
    makeCall: () throws -> T,
    writeReturn: (T) -> (),
    lowerError: (E) -> RustBuffer
) {
    do {
        try writeReturn(makeCall())
    } catch let error as E {
        callStatus.pointee.code = CALL_ERROR
        callStatus.pointee.errorBuf = lowerError(error)
    } catch {
        callStatus.pointee.code = CALL_UNEXPECTED_ERROR
        callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
    }
}
// Initial value and increment amount for handles. 
// These ensure that SWIFT handles always have the lowest bit set
fileprivate let UNIFFI_HANDLEMAP_INITIAL: UInt64 = 1
fileprivate let UNIFFI_HANDLEMAP_DELTA: UInt64 = 2

fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
    // All mutation happens with this lock held, which is why we implement @unchecked Sendable.
    private let lock = NSLock()
    private var map: [UInt64: T] = [:]
    private var currentHandle: UInt64 = UNIFFI_HANDLEMAP_INITIAL

    func insert(obj: T) -> UInt64 {
        lock.withLock {
            return doInsert(obj)
        }
    }

    // Low-level insert function, this assumes `lock` is held.
    private func doInsert(_ obj: T) -> UInt64 {
        let handle = currentHandle
        currentHandle += UNIFFI_HANDLEMAP_DELTA
        map[handle] = obj
        return handle
    }

     func get(handle: UInt64) throws -> T {
        try lock.withLock {
            guard let obj = map[handle] else {
                throw UniffiInternalError.unexpectedStaleHandle
            }
            return obj
        }
    }

     func clone(handle: UInt64) throws -> UInt64 {
        try lock.withLock {
            guard let obj = map[handle] else {
                throw UniffiInternalError.unexpectedStaleHandle
            }
            return doInsert(obj)
        }
    }

    @discardableResult
    func remove(handle: UInt64) throws -> T {
        try lock.withLock {
            guard let obj = map.removeValue(forKey: handle) else {
                throw UniffiInternalError.unexpectedStaleHandle
            }
            return obj
        }
    }

    var count: Int {
        get {
            map.count
        }
    }
}


// Public interface members begin here.
// Magic number for the Rust proxy to call using the same mechanism as every other method,
// to free the callback once it's dropped by Rust.
private let IDX_CALLBACK_FREE: Int32 = 0
// Callback return codes
private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0
private let UNIFFI_CALLBACK_ERROR: Int32 = 1
private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterBool : FfiConverter {
    typealias FfiType = Int8
    typealias SwiftType = Bool

    public static func lift(_ value: Int8) throws -> Bool {
        return value != 0
    }

    public static func lower(_ value: Bool) -> Int8 {
        return value ? 1 : 0
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
        return try lift(readInt(&buf))
    }

    public static func write(_ value: Bool, into buf: inout [UInt8]) {
        writeInt(&buf, lower(value))
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterString: FfiConverter {
    typealias SwiftType = String
    typealias FfiType = RustBuffer

    public static func lift(_ value: RustBuffer) throws -> String {
        defer {
            value.deallocate()
        }
        if value.data == nil {
            return String()
        }
        let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
        return String(bytes: bytes, encoding: String.Encoding.utf8)!
    }

    public static func lower(_ value: String) -> RustBuffer {
        return value.utf8CString.withUnsafeBufferPointer { ptr in
            // The swift string gives us int8_t, we want uint8_t.
            ptr.withMemoryRebound(to: UInt8.self) { ptr in
                // The swift string gives us a trailing null byte, we don't want it.
                let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
                return RustBuffer.from(buf)
            }
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
        let len: Int32 = try readInt(&buf)
        return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
    }

    public static func write(_ value: String, into buf: inout [UInt8]) {
        let len = Int32(value.utf8.count)
        writeInt(&buf, len)
        writeBytes(&buf, value.utf8)
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterData: FfiConverterRustBuffer {
    typealias SwiftType = Data

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
        let len: Int32 = try readInt(&buf)
        return Data(try readBytes(&buf, count: Int(len)))
    }

    public static func write(_ value: Data, into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        writeBytes(&buf, value)
    }
}




public protocol RpcClientProtocol: AnyObject, Sendable {
    
    func connectTunnel() async throws 
    
    func deleteLogFile() async throws 
    
    func disableSentry() async throws 
    
    func disableSocks5() async throws 
    
    func disconnectTunnel() async throws 
    
    func enableSentry() async throws 
    
    func enableSocks5(socks5Settings: Socks5Settings, httpRpcSettings: HttpRpcSettings, exitPoint: ExitPoint) async throws 
    
    func forgetAccount() async throws 
    
    func getAccountIdentity() async throws  -> String?
    
    func getAccountLinks(locale: String) async throws  -> ParsedAccountLinks
    
    func getAccountState() async throws  -> AccountControllerState
    
    func getAccountUsage() async throws  -> [NymVpnUsage]
    
    func getActiveDevices() async throws  -> [NymVpnDevice]
    
    func getConfig() async throws  -> VpnServiceConfig
    
    func getDefaultDns() async throws  -> [IpAddr]
    
    func getDeviceIdentity() async throws  -> String?
    
    func getDevices() async throws  -> [NymVpnDevice]
    
    func getFeatureFlags() async throws  -> FeatureFlags
    
    func getInfo() async throws  -> VpnServiceInfo
    
    func getLogPath() async throws  -> LogPath
    
    func getNetworkCompatibility() async throws  -> NetworkCompatibility?
    
    func getPrivyDerivationMessage() async throws  -> PrivyDerivationMessage
    
    func getSocks5Status() async throws  -> Socks5Status
    
    func getSystemMessages() async throws  -> [SystemMessage]
    
    func getTunnelState() async throws  -> TunnelState
    
    func isAccountStored() async throws  -> Bool
    
    func isSentryEnabled() async throws  -> Bool
    
    func listGateways(gwType: GatewayType) async throws  -> [Gateway]
    
    func listenToEvents(observer: TunnelEventObserver) async throws  -> StreamObserver
    
    func networkStatsAllowDisconnected(allowDisconnected: Bool) async throws 
    
    func networkStatsSetEnabled(enabled: Bool) async throws 
    
    func refreshAccountState() async throws 
    
    func resetDeviceIdentity(seed: Data?) async throws 
    
    func setAllowLan(allowLan: Bool) async throws 
    
    func setCustomDns(dnsServers: [IpAddr]) async throws 
    
    func setDisableIpv6(disableIpv6: Bool) async throws 
    
    func setEnableBridges(enableBridges: Bool) async throws 
    
    func setEnableCustomDns(enable: Bool) async throws 
    
    func setEnableLewesProtocol(enableLewesProtocol: Bool) async throws 
    
    func setEnableTwoHop(enableTwoHop: Bool) async throws 
    
    func setEntryPoint(entryPoint: EntryPoint) async throws 
    
    func setExitPoint(exitPoint: ExitPoint) async throws 
    
    func setNetstack(netstack: Bool) async throws 
    
    func setNetwork(network: String) async throws 
    
    func storeAccount(request: StoreAccountRequest) async throws 
    
}
open class RpcClient: RpcClientProtocol, @unchecked Sendable {
    fileprivate let handle: UInt64

    /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public struct NoHandle {
        public init() {}
    }

    // TODO: We'd like this to be `private` but for Swifty reasons,
    // we can't implement `FfiConverter` without making this `required` and we can't
    // make it `required` without making it `public`.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    required public init(unsafeFromHandle handle: UInt64) {
        self.handle = handle
    }

    // This constructor can be used to instantiate a fake object.
    // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
    //
    // - Warning:
    //     Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public init(noHandle: NoHandle) {
        self.handle = 0
    }

#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public func uniffiCloneHandle() -> UInt64 {
        return try! rustCall { uniffi_nym_vpn_rpc_uniffi_fn_clone_rpcclient(self.handle, $0) }
    }
public convenience init()async throws  {
    let handle =
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_constructor_rpcclient_new(
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_u64,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_u64,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_u64,
            liftFunc: FfiConverterTypeRpcClient_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
        
        .uniffiCloneHandle()
    self.init(unsafeFromHandle: handle)
}

    deinit {
        try! rustCall { uniffi_nym_vpn_rpc_uniffi_fn_free_rpcclient(handle, $0) }
    }

    

    
open func connectTunnel()async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_connect_tunnel(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func deleteLogFile()async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_delete_log_file(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func disableSentry()async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_disable_sentry(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func disableSocks5()async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_disable_socks5(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func disconnectTunnel()async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_disconnect_tunnel(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func enableSentry()async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_enable_sentry(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func enableSocks5(socks5Settings: Socks5Settings, httpRpcSettings: HttpRpcSettings, exitPoint: ExitPoint)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_enable_socks5(
                    self.uniffiCloneHandle(),
                    FfiConverterTypeSocks5Settings_lower(socks5Settings),FfiConverterTypeHttpRpcSettings_lower(httpRpcSettings),FfiConverterTypeExitPoint_lower(exitPoint)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func forgetAccount()async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_forget_account(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getAccountIdentity()async throws  -> String?  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_account_identity(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterOptionString.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getAccountLinks(locale: String)async throws  -> ParsedAccountLinks  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_account_links(
                    self.uniffiCloneHandle(),
                    FfiConverterString.lower(locale)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterTypeParsedAccountLinks_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getAccountState()async throws  -> AccountControllerState  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_account_state(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterTypeAccountControllerState_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getAccountUsage()async throws  -> [NymVpnUsage]  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_account_usage(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterSequenceTypeNymVpnUsage.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getActiveDevices()async throws  -> [NymVpnDevice]  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_active_devices(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterSequenceTypeNymVpnDevice.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getConfig()async throws  -> VpnServiceConfig  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_config(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterTypeVpnServiceConfig_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getDefaultDns()async throws  -> [IpAddr]  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_default_dns(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterSequenceTypeIpAddr.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getDeviceIdentity()async throws  -> String?  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_device_identity(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterOptionString.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getDevices()async throws  -> [NymVpnDevice]  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_devices(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterSequenceTypeNymVpnDevice.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getFeatureFlags()async throws  -> FeatureFlags  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_feature_flags(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_u64,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_u64,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_u64,
            liftFunc: FfiConverterTypeFeatureFlags_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getInfo()async throws  -> VpnServiceInfo  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_info(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterTypeVpnServiceInfo_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getLogPath()async throws  -> LogPath  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_log_path(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterTypeLogPath_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getNetworkCompatibility()async throws  -> NetworkCompatibility?  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_network_compatibility(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterOptionTypeNetworkCompatibility.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getPrivyDerivationMessage()async throws  -> PrivyDerivationMessage  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_privy_derivation_message(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterTypePrivyDerivationMessage_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getSocks5Status()async throws  -> Socks5Status  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_socks5_status(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterTypeSocks5Status_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getSystemMessages()async throws  -> [SystemMessage]  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_system_messages(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterSequenceTypeSystemMessage.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func getTunnelState()async throws  -> TunnelState  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_get_tunnel_state(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterTypeTunnelState_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func isAccountStored()async throws  -> Bool  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_is_account_stored(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_i8,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_i8,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_i8,
            liftFunc: FfiConverterBool.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func isSentryEnabled()async throws  -> Bool  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_is_sentry_enabled(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_i8,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_i8,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_i8,
            liftFunc: FfiConverterBool.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func listGateways(gwType: GatewayType)async throws  -> [Gateway]  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_list_gateways(
                    self.uniffiCloneHandle(),
                    FfiConverterTypeGatewayType_lower(gwType)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_rust_buffer,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_rust_buffer,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_rust_buffer,
            liftFunc: FfiConverterSequenceTypeGateway.lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func listenToEvents(observer: TunnelEventObserver)async throws  -> StreamObserver  {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_listen_to_events(
                    self.uniffiCloneHandle(),
                    FfiConverterTypeTunnelEventObserver_lower(observer)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_u64,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_u64,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_u64,
            liftFunc: FfiConverterTypeStreamObserver_lift,
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func networkStatsAllowDisconnected(allowDisconnected: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_network_stats_allow_disconnected(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(allowDisconnected)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func networkStatsSetEnabled(enabled: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_network_stats_set_enabled(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(enabled)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func refreshAccountState()async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_refresh_account_state(
                    self.uniffiCloneHandle()
                    
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func resetDeviceIdentity(seed: Data?)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_reset_device_identity(
                    self.uniffiCloneHandle(),
                    FfiConverterOptionData.lower(seed)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setAllowLan(allowLan: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_allow_lan(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(allowLan)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setCustomDns(dnsServers: [IpAddr])async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_custom_dns(
                    self.uniffiCloneHandle(),
                    FfiConverterSequenceTypeIpAddr.lower(dnsServers)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setDisableIpv6(disableIpv6: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_disable_ipv6(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(disableIpv6)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setEnableBridges(enableBridges: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_enable_bridges(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(enableBridges)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setEnableCustomDns(enable: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_enable_custom_dns(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(enable)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setEnableLewesProtocol(enableLewesProtocol: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_enable_lewes_protocol(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(enableLewesProtocol)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setEnableTwoHop(enableTwoHop: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_enable_two_hop(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(enableTwoHop)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setEntryPoint(entryPoint: EntryPoint)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_entry_point(
                    self.uniffiCloneHandle(),
                    FfiConverterTypeEntryPoint_lower(entryPoint)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setExitPoint(exitPoint: ExitPoint)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_exit_point(
                    self.uniffiCloneHandle(),
                    FfiConverterTypeExitPoint_lower(exitPoint)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setNetstack(netstack: Bool)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_netstack(
                    self.uniffiCloneHandle(),
                    FfiConverterBool.lower(netstack)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func setNetwork(network: String)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_set_network(
                    self.uniffiCloneHandle(),
                    FfiConverterString.lower(network)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    
open func storeAccount(request: StoreAccountRequest)async throws   {
    return
        try  await uniffiRustCallAsync(
            rustFutureFunc: {
                uniffi_nym_vpn_rpc_uniffi_fn_method_rpcclient_store_account(
                    self.uniffiCloneHandle(),
                    FfiConverterTypeStoreAccountRequest_lower(request)
                )
            },
            pollFunc: ffi_nym_vpn_rpc_uniffi_rust_future_poll_void,
            completeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_complete_void,
            freeFunc: ffi_nym_vpn_rpc_uniffi_rust_future_free_void,
            liftFunc: { $0 },
            errorHandler: FfiConverterTypeRpcError__as_error_lift
        )
}
    

    
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeRpcClient: FfiConverter {
    typealias FfiType = UInt64
    typealias SwiftType = RpcClient

    public static func lift(_ handle: UInt64) throws -> RpcClient {
        return RpcClient(unsafeFromHandle: handle)
    }

    public static func lower(_ value: RpcClient) -> UInt64 {
        return value.uniffiCloneHandle()
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RpcClient {
        let handle: UInt64 = try readInt(&buf)
        return try lift(handle)
    }

    public static func write(_ value: RpcClient, into buf: inout [UInt8]) {
        writeInt(&buf, lower(value))
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeRpcClient_lift(_ handle: UInt64) throws -> RpcClient {
    return try FfiConverterTypeRpcClient.lift(handle)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeRpcClient_lower(_ value: RpcClient) -> UInt64 {
    return FfiConverterTypeRpcClient.lower(value)
}






public protocol RpcErrorProtocol: AnyObject, Sendable {
    
    /**
     * Returns the account error if the underlying error is an account error.
     */
    func accountError()  -> AccountCommandError?
    
}
open class RpcError: RpcErrorProtocol, @unchecked Sendable, Swift.Error, Foundation.LocalizedError, CustomStringConvertible {
    fileprivate let handle: UInt64

    /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public struct NoHandle {
        public init() {}
    }

    // TODO: We'd like this to be `private` but for Swifty reasons,
    // we can't implement `FfiConverter` without making this `required` and we can't
    // make it `required` without making it `public`.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    required public init(unsafeFromHandle handle: UInt64) {
        self.handle = handle
    }

    // This constructor can be used to instantiate a fake object.
    // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
    //
    // - Warning:
    //     Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public init(noHandle: NoHandle) {
        self.handle = 0
    }

#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public func uniffiCloneHandle() -> UInt64 {
        return try! rustCall { uniffi_nym_vpn_rpc_uniffi_fn_clone_rpcerror(self.handle, $0) }
    }
    // No primary constructor declared for this class.

    deinit {
        try! rustCall { uniffi_nym_vpn_rpc_uniffi_fn_free_rpcerror(handle, $0) }
    }

    

    
    /**
     * Returns the account error if the underlying error is an account error.
     */
open func accountError() -> AccountCommandError?  {
    return try!  FfiConverterOptionTypeAccountCommandError.lift(try! rustCall() {
    uniffi_nym_vpn_rpc_uniffi_fn_method_rpcerror_account_error(
            self.uniffiCloneHandle(),$0
    )
})
}
    

    
// The local Rust `Display` implementation.
public var description: String {
    return try!  FfiConverterString.lift(
        try! rustCall() {
    uniffi_nym_vpn_rpc_uniffi_fn_method_rpcerror_uniffi_trait_display(
            self.uniffiCloneHandle(),$0
    )
}
    )
}
    
    public var errorDescription: String? {
        String(reflecting: self)
    }
    
    
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeRpcError: FfiConverter {
    typealias FfiType = UInt64
    typealias SwiftType = RpcError

    public static func lift(_ handle: UInt64) throws -> RpcError {
        return RpcError(unsafeFromHandle: handle)
    }

    public static func lower(_ value: RpcError) -> UInt64 {
        return value.uniffiCloneHandle()
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RpcError {
        let handle: UInt64 = try readInt(&buf)
        return try lift(handle)
    }

    public static func write(_ value: RpcError, into buf: inout [UInt8]) {
        writeInt(&buf, lower(value))
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeRpcError_lift(_ handle: UInt64) throws -> RpcError {
    return try FfiConverterTypeRpcError.lift(handle)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeRpcError_lower(_ value: RpcError) -> UInt64 {
    return FfiConverterTypeRpcError.lower(value)
}




#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeRpcError__as_error: FfiConverterRustBuffer {
    public static func lift(_ buf: RustBuffer) throws -> RpcError {
        var reader = createReader(data: Data(rustBuffer: buf))
        return try FfiConverterTypeRpcError.read(from: &reader)
    }

    public static func lower(_ value: RpcError) -> RustBuffer {
        fatalError("not implemented")
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RpcError {
        fatalError("not implemented")
    }

    public static func write(_ value: RpcError, into buf: inout [UInt8]) {
        fatalError("not implemented")
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeRpcError__as_error_lift(_ buf: RustBuffer) throws -> RpcError {
    return try FfiConverterTypeRpcError__as_error.lift(buf)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeRpcError__as_error_lower(_ value: RpcError) -> RustBuffer {
    return FfiConverterTypeRpcError__as_error.lower(value)
}




public protocol StreamObserverProtocol: AnyObject, Sendable {
    
    func cancel() 
    
}
open class StreamObserver: StreamObserverProtocol, @unchecked Sendable {
    fileprivate let handle: UInt64

    /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public struct NoHandle {
        public init() {}
    }

    // TODO: We'd like this to be `private` but for Swifty reasons,
    // we can't implement `FfiConverter` without making this `required` and we can't
    // make it `required` without making it `public`.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    required public init(unsafeFromHandle handle: UInt64) {
        self.handle = handle
    }

    // This constructor can be used to instantiate a fake object.
    // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
    //
    // - Warning:
    //     Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public init(noHandle: NoHandle) {
        self.handle = 0
    }

#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public func uniffiCloneHandle() -> UInt64 {
        return try! rustCall { uniffi_nym_vpn_rpc_uniffi_fn_clone_streamobserver(self.handle, $0) }
    }
    // No primary constructor declared for this class.

    deinit {
        try! rustCall { uniffi_nym_vpn_rpc_uniffi_fn_free_streamobserver(handle, $0) }
    }

    

    
open func cancel()  {try! rustCall() {
    uniffi_nym_vpn_rpc_uniffi_fn_method_streamobserver_cancel(
            self.uniffiCloneHandle(),$0
    )
}
}
    

    
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeStreamObserver: FfiConverter {
    typealias FfiType = UInt64
    typealias SwiftType = StreamObserver

    public static func lift(_ handle: UInt64) throws -> StreamObserver {
        return StreamObserver(unsafeFromHandle: handle)
    }

    public static func lower(_ value: StreamObserver) -> UInt64 {
        return value.uniffiCloneHandle()
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> StreamObserver {
        let handle: UInt64 = try readInt(&buf)
        return try lift(handle)
    }

    public static func write(_ value: StreamObserver, into buf: inout [UInt8]) {
        writeInt(&buf, lower(value))
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeStreamObserver_lift(_ handle: UInt64) throws -> StreamObserver {
    return try FfiConverterTypeStreamObserver.lift(handle)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeStreamObserver_lower(_ value: StreamObserver) -> UInt64 {
    return FfiConverterTypeStreamObserver.lower(value)
}






public protocol TunnelEventObserver: AnyObject, Sendable {
    
    func onTunnelEvent(event: TunnelEvent) 
    
    func onClose() 
    
}
open class TunnelEventObserverImpl: TunnelEventObserver, @unchecked Sendable {
    fileprivate let handle: UInt64

    /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public struct NoHandle {
        public init() {}
    }

    // TODO: We'd like this to be `private` but for Swifty reasons,
    // we can't implement `FfiConverter` without making this `required` and we can't
    // make it `required` without making it `public`.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    required public init(unsafeFromHandle handle: UInt64) {
        self.handle = handle
    }

    // This constructor can be used to instantiate a fake object.
    // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
    //
    // - Warning:
    //     Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public init(noHandle: NoHandle) {
        self.handle = 0
    }

#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public func uniffiCloneHandle() -> UInt64 {
        return try! rustCall { uniffi_nym_vpn_rpc_uniffi_fn_clone_tunneleventobserver(self.handle, $0) }
    }
    // No primary constructor declared for this class.

    deinit {
        try! rustCall { uniffi_nym_vpn_rpc_uniffi_fn_free_tunneleventobserver(handle, $0) }
    }

    

    
open func onTunnelEvent(event: TunnelEvent)  {try! rustCall() {
    uniffi_nym_vpn_rpc_uniffi_fn_method_tunneleventobserver_on_tunnel_event(
            self.uniffiCloneHandle(),
        FfiConverterTypeTunnelEvent_lower(event),$0
    )
}
}
    
open func onClose()  {try! rustCall() {
    uniffi_nym_vpn_rpc_uniffi_fn_method_tunneleventobserver_on_close(
            self.uniffiCloneHandle(),$0
    )
}
}
    

    
}



// Put the implementation in a struct so we don't pollute the top-level namespace
fileprivate struct UniffiCallbackInterfaceTunnelEventObserver {

    // Create the VTable using a series of closures.
    // Swift automatically converts these into C callback functions.
    //
    // This creates 1-element array, since this seems to be the only way to construct a const
    // pointer that we can pass to the Rust code.
    static let vtable: [UniffiVTableCallbackInterfaceTunnelEventObserver] = [UniffiVTableCallbackInterfaceTunnelEventObserver(
        uniffiFree: { (uniffiHandle: UInt64) -> () in
            do {
                try FfiConverterTypeTunnelEventObserver.handleMap.remove(handle: uniffiHandle)
            } catch {
                print("Uniffi callback interface TunnelEventObserver: handle missing in uniffiFree")
            }
        },
        uniffiClone: { (uniffiHandle: UInt64) -> UInt64 in
            do {
                return try FfiConverterTypeTunnelEventObserver.handleMap.clone(handle: uniffiHandle)
            } catch {
                fatalError("Uniffi callback interface TunnelEventObserver: handle missing in uniffiClone")
            }
        },
        onTunnelEvent: { (
            uniffiHandle: UInt64,
            event: RustBuffer,
            uniffiOutReturn: UnsafeMutableRawPointer,
            uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
        ) in
            let makeCall = {
                () throws -> () in
                guard let uniffiObj = try? FfiConverterTypeTunnelEventObserver.handleMap.get(handle: uniffiHandle) else {
                    throw UniffiInternalError.unexpectedStaleHandle
                }
                return uniffiObj.onTunnelEvent(
                     event: try FfiConverterTypeTunnelEvent_lift(event)
                )
            }

            
            let writeReturn = { () }
            uniffiTraitInterfaceCall(
                callStatus: uniffiCallStatus,
                makeCall: makeCall,
                writeReturn: writeReturn
            )
        },
        onClose: { (
            uniffiHandle: UInt64,
            uniffiOutReturn: UnsafeMutableRawPointer,
            uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
        ) in
            let makeCall = {
                () throws -> () in
                guard let uniffiObj = try? FfiConverterTypeTunnelEventObserver.handleMap.get(handle: uniffiHandle) else {
                    throw UniffiInternalError.unexpectedStaleHandle
                }
                return uniffiObj.onClose(
                )
            }

            
            let writeReturn = { () }
            uniffiTraitInterfaceCall(
                callStatus: uniffiCallStatus,
                makeCall: makeCall,
                writeReturn: writeReturn
            )
        }
    )]
}

private func uniffiCallbackInitTunnelEventObserver() {
    uniffi_nym_vpn_rpc_uniffi_fn_init_callback_vtable_tunneleventobserver(UniffiCallbackInterfaceTunnelEventObserver.vtable)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeTunnelEventObserver: FfiConverter {
    fileprivate static let handleMap = UniffiHandleMap<TunnelEventObserver>()

    typealias FfiType = UInt64
    typealias SwiftType = TunnelEventObserver

    public static func lift(_ handle: UInt64) throws -> TunnelEventObserver {
        if ((handle & 1) == 0) {
            // Rust-generated handle, construct a new class that uses the handle to implement the
            // interface
            return TunnelEventObserverImpl(unsafeFromHandle: handle)
        } else {
            // Swift-generated handle, get the object from the handle map
            return try handleMap.remove(handle: handle)
        }
    }

    public static func lower(_ value: TunnelEventObserver) -> UInt64 {
         if let rustImpl = value as? TunnelEventObserverImpl {
             // Rust-implemented object.  Clone the handle and return it
            return rustImpl.uniffiCloneHandle()
         } else {
            // Swift object, generate a new vtable handle and return that.
            return handleMap.insert(obj: value)
         }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TunnelEventObserver {
        let handle: UInt64 = try readInt(&buf)
        return try lift(handle)
    }

    public static func write(_ value: TunnelEventObserver, into buf: inout [UInt8]) {
        writeInt(&buf, lower(value))
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeTunnelEventObserver_lift(_ handle: UInt64) throws -> TunnelEventObserver {
    return try FfiConverterTypeTunnelEventObserver.lift(handle)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeTunnelEventObserver_lower(_ value: TunnelEventObserver) -> UInt64 {
    return FfiConverterTypeTunnelEventObserver.lower(value)
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
    typealias SwiftType = String?

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterString.write(value, into: &buf)
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
        switch try readInt(&buf) as Int8 {
        case 0: return nil
        case 1: return try FfiConverterString.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionData: FfiConverterRustBuffer {
    typealias SwiftType = Data?

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterData.write(value, into: &buf)
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
        switch try readInt(&buf) as Int8 {
        case 0: return nil
        case 1: return try FfiConverterData.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeNetworkCompatibility: FfiConverterRustBuffer {
    typealias SwiftType = NetworkCompatibility?

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterTypeNetworkCompatibility.write(value, into: &buf)
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
        switch try readInt(&buf) as Int8 {
        case 0: return nil
        case 1: return try FfiConverterTypeNetworkCompatibility.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeAccountCommandError: FfiConverterRustBuffer {
    typealias SwiftType = AccountCommandError?

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterTypeAccountCommandError.write(value, into: &buf)
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
        switch try readInt(&buf) as Int8 {
        case 0: return nil
        case 1: return try FfiConverterTypeAccountCommandError.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeGateway: FfiConverterRustBuffer {
    typealias SwiftType = [Gateway]

    public static func write(_ value: [Gateway], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for item in value {
            FfiConverterTypeGateway.write(item, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Gateway] {
        let len: Int32 = try readInt(&buf)
        var seq = [Gateway]()
        seq.reserveCapacity(Int(len))
        for _ in 0 ..< len {
            seq.append(try FfiConverterTypeGateway.read(from: &buf))
        }
        return seq
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeNymVpnDevice: FfiConverterRustBuffer {
    typealias SwiftType = [NymVpnDevice]

    public static func write(_ value: [NymVpnDevice], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for item in value {
            FfiConverterTypeNymVpnDevice.write(item, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [NymVpnDevice] {
        let len: Int32 = try readInt(&buf)
        var seq = [NymVpnDevice]()
        seq.reserveCapacity(Int(len))
        for _ in 0 ..< len {
            seq.append(try FfiConverterTypeNymVpnDevice.read(from: &buf))
        }
        return seq
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeNymVpnUsage: FfiConverterRustBuffer {
    typealias SwiftType = [NymVpnUsage]

    public static func write(_ value: [NymVpnUsage], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for item in value {
            FfiConverterTypeNymVpnUsage.write(item, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [NymVpnUsage] {
        let len: Int32 = try readInt(&buf)
        var seq = [NymVpnUsage]()
        seq.reserveCapacity(Int(len))
        for _ in 0 ..< len {
            seq.append(try FfiConverterTypeNymVpnUsage.read(from: &buf))
        }
        return seq
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeSystemMessage: FfiConverterRustBuffer {
    typealias SwiftType = [SystemMessage]

    public static func write(_ value: [SystemMessage], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for item in value {
            FfiConverterTypeSystemMessage.write(item, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [SystemMessage] {
        let len: Int32 = try readInt(&buf)
        var seq = [SystemMessage]()
        seq.reserveCapacity(Int(len))
        for _ in 0 ..< len {
            seq.append(try FfiConverterTypeSystemMessage.read(from: &buf))
        }
        return seq
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeIpAddr: FfiConverterRustBuffer {
    typealias SwiftType = [IpAddr]

    public static func write(_ value: [IpAddr], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for item in value {
            FfiConverterTypeIpAddr.write(item, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [IpAddr] {
        let len: Int32 = try readInt(&buf)
        var seq = [IpAddr]()
        seq.reserveCapacity(Int(len))
        for _ in 0 ..< len {
            seq.append(try FfiConverterTypeIpAddr.read(from: &buf))
        }
        return seq
    }
}
private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0
private let UNIFFI_RUST_FUTURE_POLL_WAKE: Int8 = 1

fileprivate let uniffiContinuationHandleMap = UniffiHandleMap<UnsafeContinuation<Int8, Never>>()

fileprivate func uniffiRustCallAsync<F, T>(
    rustFutureFunc: () -> UInt64,
    pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> (),
    completeFunc: (UInt64, UnsafeMutablePointer<RustCallStatus>) -> F,
    freeFunc: (UInt64) -> (),
    liftFunc: (F) throws -> T,
    errorHandler: ((RustBuffer) throws -> Swift.Error)?
) async throws -> T {
    // Make sure to call the ensure init function since future creation doesn't have a
    // RustCallStatus param, so doesn't use makeRustCall()
    uniffiEnsureNymVpnRpcUniffiInitialized()
    let rustFuture = rustFutureFunc()
    defer {
        freeFunc(rustFuture)
    }
    var pollResult: Int8;
    repeat {
        pollResult = await withUnsafeContinuation {
            pollFunc(
                rustFuture,
                { handle, pollResult in
                    uniffiFutureContinuationCallback(handle: handle, pollResult: pollResult)
                },
                uniffiContinuationHandleMap.insert(obj: $0)
            )
        }
    } while pollResult != UNIFFI_RUST_FUTURE_POLL_READY

    return try liftFunc(makeRustCall(
        { completeFunc(rustFuture, $0) },
        errorHandler: errorHandler
    ))
}

// Callback handlers for an async calls.  These are invoked by Rust when the future is ready.  They
// lift the return value or error and resume the suspended function.
fileprivate func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) {
    if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) {
        continuation.resume(returning: pollResult)
    } else {
        print("uniffiFutureContinuationCallback invalid handle")
    }
}

private enum InitializationResult {
    case ok
    case contractVersionMismatch
    case apiChecksumMismatch
}
// Use a global variable to perform the versioning checks. Swift ensures that
// the code inside is only computed once.
private let initializationResult: InitializationResult = {
    // Get the bindings contract version from our ComponentInterface
    let bindings_contract_version = 30
    // Get the scaffolding contract version by calling the into the dylib
    let scaffolding_contract_version = ffi_nym_vpn_rpc_uniffi_uniffi_contract_version()
    if bindings_contract_version != scaffolding_contract_version {
        return InitializationResult.contractVersionMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_connect_tunnel() != 31660) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_delete_log_file() != 15427) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_disable_sentry() != 31931) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_disable_socks5() != 44415) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_disconnect_tunnel() != 56182) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_enable_sentry() != 47312) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_enable_socks5() != 59506) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_forget_account() != 58918) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_account_identity() != 30080) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_account_links() != 54903) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_account_state() != 58553) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_account_usage() != 64183) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_active_devices() != 34448) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_config() != 4409) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_default_dns() != 50594) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_device_identity() != 16861) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_devices() != 25520) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_feature_flags() != 36) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_info() != 19419) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_log_path() != 43398) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_network_compatibility() != 64677) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_privy_derivation_message() != 23280) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_socks5_status() != 54093) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_system_messages() != 34147) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_get_tunnel_state() != 63203) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_is_account_stored() != 41253) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_is_sentry_enabled() != 12881) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_list_gateways() != 6142) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_listen_to_events() != 25996) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_network_stats_allow_disconnected() != 39348) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_network_stats_set_enabled() != 55770) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_refresh_account_state() != 34261) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_reset_device_identity() != 7837) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_allow_lan() != 38553) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_custom_dns() != 17539) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_disable_ipv6() != 6942) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_enable_bridges() != 43475) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_enable_custom_dns() != 17998) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_enable_lewes_protocol() != 42987) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_enable_two_hop() != 33790) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_entry_point() != 13869) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_exit_point() != 8819) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_netstack() != 28829) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_set_network() != 20289) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcclient_store_account() != 34801) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_rpcerror_account_error() != 54984) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_streamobserver_cancel() != 13259) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_tunneleventobserver_on_tunnel_event() != 28101) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_method_tunneleventobserver_on_close() != 2743) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_nym_vpn_rpc_uniffi_checksum_constructor_rpcclient_new() != 43246) {
        return InitializationResult.apiChecksumMismatch
    }

    uniffiCallbackInitTunnelEventObserver()
    uniffiEnsureNymVpnLibTypesInitialized()
    return InitializationResult.ok
}()

// Make the ensure init function public so that other modules which have external type references to
// our types can call it.
public func uniffiEnsureNymVpnRpcUniffiInitialized() {
    switch initializationResult {
    case .ok:
        break
    case .contractVersionMismatch:
        fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
    case .apiChecksumMismatch:
        fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    }
}

// swiftlint:enable all