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

@file:Suppress("NAME_SHADOWING")

package mozilla.appservices.autofill

// Common helper code.
//
// Ideally this would live in a separate .kt file where it can be unittested etc
// in isolation, and perhaps even published as a re-useable package.
//
// However, it's important that the details of how this helper code works (e.g. the
// way that different builtin types are passed across the FFI) exactly match what's
// expected by the Rust code on the other side of the interface. In practice right
// now that means coming from the exact some version of `uniffi` that was used to
// compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
// helpers directly inline like we're doing here.

import com.sun.jna.Library
import com.sun.jna.IntegerType
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure
import com.sun.jna.Callback
import com.sun.jna.ptr.*
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.nio.CharBuffer
import java.nio.charset.CodingErrorAction
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean

// This is a helper for safely working with byte buffers returned from the Rust code.
// A rust-owned buffer is represented by its capacity, its current length, and a
// pointer to the underlying data.

/**
 * @suppress
 */
@Structure.FieldOrder("capacity", "len", "data")
open class RustBuffer : Structure() {
    // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
    // When dealing with these fields, make sure to call `toULong()`.
    @JvmField var capacity: Long = 0
    @JvmField var len: Long = 0
    @JvmField var data: Pointer? = null

    class ByValue: RustBuffer(), Structure.ByValue
    class ByReference: RustBuffer(), Structure.ByReference

   internal fun setValue(other: RustBuffer) {
        capacity = other.capacity
        len = other.len
        data = other.data
    }

    companion object {
        internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
            // Note: need to convert the size to a `Long` value to make this work with JVM.
            UniffiLib.ffi_autofill_rustbuffer_alloc(size.toLong(), status)
        }.also {
            if(it.data == null) {
               throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
           }
        }

        internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
            var buf = RustBuffer.ByValue()
            buf.capacity = capacity.toLong()
            buf.len = len.toLong()
            buf.data = data
            return buf
        }

        internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
            UniffiLib.ffi_autofill_rustbuffer_free(buf, status)
        }
    }

    @Suppress("TooGenericExceptionThrown")
    fun asByteBuffer() =
        this.data?.getByteBuffer(0, this.len)?.also {
            it.order(ByteOrder.BIG_ENDIAN)
        }
}

// This is a helper for safely passing byte references into the rust code.
// It's not actually used at the moment, because there aren't many things that you
// can take a direct pointer to in the JVM, and if we're going to copy something
// then we might as well copy it into a `RustBuffer`. But it's here for API
// completeness.

@Structure.FieldOrder("len", "data")
internal open class ForeignBytes : Structure() {
    @JvmField var len: Int = 0
    @JvmField var data: Pointer? = null

    class ByValue : ForeignBytes(), Structure.ByValue
}
/**
 * The FfiConverter interface handles converter types to and from the FFI
 *
 * All implementing objects should be public to support external types.  When a
 * type is external we need to import it's FfiConverter.
 *
 * @suppress
 */
public interface FfiConverter<KotlinType, FfiType> {
    // Convert an FFI type to a Kotlin type
    fun lift(value: FfiType): KotlinType

    // Convert an Kotlin type to an FFI type
    fun lower(value: KotlinType): FfiType

    // Read a Kotlin type from a `ByteBuffer`
    fun read(buf: ByteBuffer): KotlinType

    // Calculate bytes to allocate when creating a `RustBuffer`
    //
    // This must return at least as many bytes as the write() function will
    // write. It can return more bytes than needed, for example when writing
    // Strings we can't know the exact bytes needed until we the UTF-8
    // encoding, so we pessimistically allocate the largest size possible (3
    // bytes per codepoint).  Allocating extra bytes is not really a big deal
    // because the `RustBuffer` is short-lived.
    fun allocationSize(value: KotlinType): ULong

    // Write a Kotlin type to a `ByteBuffer`
    fun write(value: KotlinType, buf: ByteBuffer)

    // Lower a value into a `RustBuffer`
    //
    // This method lowers a value into a `RustBuffer` rather than the normal
    // FfiType.  It's used by the callback interface code.  Callback interface
    // returns are always serialized into a `RustBuffer` regardless of their
    // normal FFI type.
    fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
        val rbuf = RustBuffer.alloc(allocationSize(value))
        try {
            val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
                it.order(ByteOrder.BIG_ENDIAN)
            }
            write(value, bbuf)
            rbuf.writeField("len", bbuf.position().toLong())
            return rbuf
        } catch (e: Throwable) {
            RustBuffer.free(rbuf)
            throw e
        }
    }

    // Lift a value from a `RustBuffer`.
    //
    // This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
    // It's currently only used by the `FfiConverterRustBuffer` class below.
    fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
        val byteBuf = rbuf.asByteBuffer()!!
        try {
           val item = read(byteBuf)
           if (byteBuf.hasRemaining()) {
               throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
           }
           return item
        } finally {
            RustBuffer.free(rbuf)
        }
    }
}

/**
 * FfiConverter that uses `RustBuffer` as the FfiType
 *
 * @suppress
 */
public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
    override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
    override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
}
// A handful of classes and functions to support the generated data structures.
// This would be a good candidate for isolating in its own ffi-support lib.

internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
internal const val UNIFFI_CALL_ERROR = 1.toByte()
internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()

@Structure.FieldOrder("code", "error_buf")
internal open class UniffiRustCallStatus : Structure() {
    @JvmField var code: Byte = 0
    @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()

    class ByValue: UniffiRustCallStatus(), Structure.ByValue

    fun isSuccess(): Boolean {
        return code == UNIFFI_CALL_SUCCESS
    }

    fun isError(): Boolean {
        return code == UNIFFI_CALL_ERROR
    }

    fun isPanic(): Boolean {
        return code == UNIFFI_CALL_UNEXPECTED_ERROR
    }

    companion object {
        fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
            val callStatus = UniffiRustCallStatus.ByValue()
            callStatus.code = code
            callStatus.error_buf = errorBuf
            return callStatus
        }
    }
}

class InternalException(message: String) : kotlin.Exception(message)

/**
 * Each top-level error class has a companion object that can lift the error from the call status's rust buffer
 *
 * @suppress
 */
interface UniffiRustCallStatusErrorHandler<E> {
    fun lift(error_buf: RustBuffer.ByValue): E;
}

// Helpers for calling Rust
// In practice we usually need to be synchronized to call this safely, so it doesn't
// synchronize itself

// Call a rust function that returns a Result<>.  Pass in the Error class companion that corresponds to the Err
private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
    var status = UniffiRustCallStatus()
    val return_value = callback(status)
    uniffiCheckCallStatus(errorHandler, status)
    return return_value
}

// Check UniffiRustCallStatus and throw an error if the call wasn't successful
private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
    if (status.isSuccess()) {
        return
    } else if (status.isError()) {
        throw errorHandler.lift(status.error_buf)
    } else if (status.isPanic()) {
        // 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 (status.error_buf.len > 0) {
            throw InternalException(FfiConverterString.lift(status.error_buf))
        } else {
            throw InternalException("Rust panic")
        }
    } else {
        throw InternalException("Unknown rust call status: $status.code")
    }
}

/**
 * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
 *
 * @suppress
 */
object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
    override fun lift(error_buf: RustBuffer.ByValue): InternalException {
        RustBuffer.free(error_buf)
        return InternalException("Unexpected CALL_ERROR")
    }
}

// Call a rust function that returns a plain value
private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
    return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
}

internal inline fun<T> uniffiTraitInterfaceCall(
    callStatus: UniffiRustCallStatus,
    makeCall: () -> T,
    writeReturn: (T) -> Unit,
) {
    try {
        writeReturn(makeCall())
    } catch(e: kotlin.Exception) {
        val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
        callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
        callStatus.error_buf = FfiConverterString.lower(err)
    }
}

internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
    callStatus: UniffiRustCallStatus,
    makeCall: () -> T,
    writeReturn: (T) -> Unit,
    lowerError: (E) -> RustBuffer.ByValue
) {
    try {
        writeReturn(makeCall())
    } catch(e: kotlin.Exception) {
        if (e is E) {
            callStatus.code = UNIFFI_CALL_ERROR
            callStatus.error_buf = lowerError(e)
        } else {
            val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
            callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
            callStatus.error_buf = FfiConverterString.lower(err)
        }
    }
}
// Initial value and increment amount for handles. 
// These ensure that Kotlin-generated handles always have the lowest bit set
private const val UNIFFI_HANDLEMAP_INITIAL = 1.toLong()
private const val UNIFFI_HANDLEMAP_DELTA = 2.toLong()

// Map handles to objects
//
// This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
internal class UniffiHandleMap<T: Any> {
    private val map = ConcurrentHashMap<Long, T>()
    // Start 
    private val counter = java.util.concurrent.atomic.AtomicLong(UNIFFI_HANDLEMAP_INITIAL)

    val size: Int
        get() = map.size

    // Insert a new object into the handle map and get a handle for it
    fun insert(obj: T): Long {
        val handle = counter.getAndAdd(UNIFFI_HANDLEMAP_DELTA)
        map.put(handle, obj)
        return handle
    }

    // Clone a handle, creating a new one
    fun clone(handle: Long): Long {
        val obj = map.get(handle) ?: throw InternalException("UniffiHandleMap.clone: Invalid handle")
        return insert(obj)
    }

    // Get an object from the handle map
    fun get(handle: Long): T {
        return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
    }

    // Remove an entry from the handlemap and get the Kotlin object back
    fun remove(handle: Long): T {
        return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
    }
}

// Contains loading, initialization code,
// and the FFI Function declarations in a com.sun.jna.Library.
@Synchronized
private fun findLibraryName(componentName: String): String {
    val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
    if (libOverride != null) {
        return libOverride
    }
    return "megazord"
}

// Define FFI callback types
internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
    fun callback(`data`: Long,`pollResult`: Byte,)
}
internal interface UniffiForeignFutureDroppedCallback : com.sun.jna.Callback {
    fun callback(`handle`: Long,)
}
internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
    fun callback(`handle`: Long,)
}
internal interface UniffiCallbackInterfaceClone : com.sun.jna.Callback {
    fun callback(`handle`: Long,)
    : Long
}
@Structure.FieldOrder("handle", "free")
internal open class UniffiForeignFutureDroppedCallbackStruct(
    @JvmField internal var `handle`: Long = 0.toLong(),
    @JvmField internal var `free`: UniffiForeignFutureDroppedCallback? = null,
) : Structure() {
    class UniffiByValue(
        `handle`: Long = 0.toLong(),
        `free`: UniffiForeignFutureDroppedCallback? = null,
    ): UniffiForeignFutureDroppedCallbackStruct(`handle`,`free`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureDroppedCallbackStruct) {
        `handle` = other.`handle`
        `free` = other.`free`
    }

}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU8(
    @JvmField internal var `returnValue`: Byte = 0.toByte(),
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Byte = 0.toByte(),
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultU8(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultU8) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU8.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI8(
    @JvmField internal var `returnValue`: Byte = 0.toByte(),
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Byte = 0.toByte(),
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultI8(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultI8) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI8.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU16(
    @JvmField internal var `returnValue`: Short = 0.toShort(),
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Short = 0.toShort(),
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultU16(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultU16) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU16.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI16(
    @JvmField internal var `returnValue`: Short = 0.toShort(),
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Short = 0.toShort(),
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultI16(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultI16) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI16.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU32(
    @JvmField internal var `returnValue`: Int = 0,
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Int = 0,
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultU32(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultU32) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI32(
    @JvmField internal var `returnValue`: Int = 0,
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Int = 0,
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultI32(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultI32) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU64(
    @JvmField internal var `returnValue`: Long = 0.toLong(),
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Long = 0.toLong(),
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultU64(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultU64) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI64(
    @JvmField internal var `returnValue`: Long = 0.toLong(),
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Long = 0.toLong(),
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultI64(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultI64) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultF32(
    @JvmField internal var `returnValue`: Float = 0.0f,
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Float = 0.0f,
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultF32(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultF32) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultF64(
    @JvmField internal var `returnValue`: Double = 0.0,
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: Double = 0.0,
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultF64(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultF64) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultRustBuffer(
    @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultRustBuffer) {
        `returnValue` = other.`returnValue`
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultRustBuffer.UniffiByValue,)
}
@Structure.FieldOrder("callStatus")
internal open class UniffiForeignFutureResultVoid(
    @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
    class UniffiByValue(
        `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    ): UniffiForeignFutureResultVoid(`callStatus`,), Structure.ByValue

   internal fun uniffiSetValue(other: UniffiForeignFutureResultVoid) {
        `callStatus` = other.`callStatus`
    }

}
internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
    fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultVoid.UniffiByValue,)
}

// A JNA Library to expose the extern-C FFI definitions.
// This is an implementation detail which will be called internally by the public API.

// For large crates we prevent `MethodTooLargeException` (see #2340)
// N.B. the name of the extension is very misleading, since it is
// rather `InterfaceTooLargeException`, caused by too many methods
// in the interface for large crates.
//
// By splitting the otherwise huge interface into two parts
// * UniffiLib (this)
// * IntegrityCheckingUniffiLib
// And all checksum methods are put into `IntegrityCheckingUniffiLib`
// we allow for ~2x as many methods in the UniffiLib interface.
//
// Note: above all written when we used JNA's `loadIndirect` etc.
// We now use JNA's "direct mapping" - unclear if same considerations apply exactly.
internal object IntegrityCheckingUniffiLib {
    init {
        Native.register(IntegrityCheckingUniffiLib::class.java, findLibraryName(componentName = "autofill"))
        uniffiCheckContractApiVersion(this)
    }
    external fun uniffi_autofill_checksum_func_create_autofill_key(
    ): Short
    external fun uniffi_autofill_checksum_func_decrypt_string(
    ): Short
    external fun uniffi_autofill_checksum_func_encrypt_string(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_apply(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_ensure_current_sync_id(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_last_sync(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_prepare_for_sync(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_reset(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_reset_sync_id(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_set_last_sync(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_set_uploaded(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_store_incoming(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_sync_finished(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_sync_id(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_sync_started(
    ): Short
    external fun uniffi_autofill_checksum_method_addressesbridgedengine_wipe(
    ): Short
    external fun uniffi_autofill_checksum_method_store_add_address(
    ): Short
    external fun uniffi_autofill_checksum_method_store_add_address_with_meta(
    ): Short
    external fun uniffi_autofill_checksum_method_store_add_credit_card(
    ): Short
    external fun uniffi_autofill_checksum_method_store_add_many_address_tombstones(
    ): Short
    external fun uniffi_autofill_checksum_method_store_add_many_addresses_with_meta(
    ): Short
    external fun uniffi_autofill_checksum_method_store_add_passport(
    ): Short
    external fun uniffi_autofill_checksum_method_store_addresses_bridged_engine(
    ): Short
    external fun uniffi_autofill_checksum_method_store_count_all_addresses(
    ): Short
    external fun uniffi_autofill_checksum_method_store_count_all_credit_cards(
    ): Short
    external fun uniffi_autofill_checksum_method_store_count_all_passports(
    ): Short
    external fun uniffi_autofill_checksum_method_store_delete_address(
    ): Short
    external fun uniffi_autofill_checksum_method_store_delete_all_addresses(
    ): Short
    external fun uniffi_autofill_checksum_method_store_delete_credit_card(
    ): Short
    external fun uniffi_autofill_checksum_method_store_delete_passport(
    ): Short
    external fun uniffi_autofill_checksum_method_store_get_address(
    ): Short
    external fun uniffi_autofill_checksum_method_store_get_all_addresses(
    ): Short
    external fun uniffi_autofill_checksum_method_store_get_all_credit_cards(
    ): Short
    external fun uniffi_autofill_checksum_method_store_get_all_passports(
    ): Short
    external fun uniffi_autofill_checksum_method_store_get_credit_card(
    ): Short
    external fun uniffi_autofill_checksum_method_store_get_passport(
    ): Short
    external fun uniffi_autofill_checksum_method_store_register_with_sync_manager(
    ): Short
    external fun uniffi_autofill_checksum_method_store_run_maintenance(
    ): Short
    external fun uniffi_autofill_checksum_method_store_scrub_encrypted_data(
    ): Short
    external fun uniffi_autofill_checksum_method_store_scrub_undecryptable_credit_card_data_for_remote_replacement(
    ): Short
    external fun uniffi_autofill_checksum_method_store_shutdown(
    ): Short
    external fun uniffi_autofill_checksum_method_store_touch_address(
    ): Short
    external fun uniffi_autofill_checksum_method_store_touch_credit_card(
    ): Short
    external fun uniffi_autofill_checksum_method_store_touch_passport(
    ): Short
    external fun uniffi_autofill_checksum_method_store_update_address(
    ): Short
    external fun uniffi_autofill_checksum_method_store_update_address_with_meta(
    ): Short
    external fun uniffi_autofill_checksum_method_store_update_credit_card(
    ): Short
    external fun uniffi_autofill_checksum_method_store_update_passport(
    ): Short
    external fun uniffi_autofill_checksum_constructor_store_new(
    ): Short
    external fun ffi_autofill_uniffi_contract_version(
    ): Int

        
}

internal object UniffiLib {
    
    // The Cleaner for the whole library
    internal val CLEANER: UniffiCleaner by lazy {
        UniffiCleaner.create()
    }
    

    init {
        Native.register(UniffiLib::class.java, findLibraryName(componentName = "autofill"))
        
    }
    external fun uniffi_autofill_fn_clone_addressesbridgedengine(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun uniffi_autofill_fn_free_addressesbridgedengine(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_addressesbridgedengine_apply(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_addressesbridgedengine_ensure_current_sync_id(`ptr`: Long,`newSyncId`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_addressesbridgedengine_last_sync(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun uniffi_autofill_fn_method_addressesbridgedengine_prepare_for_sync(`ptr`: Long,`clientData`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_addressesbridgedengine_reset(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_addressesbridgedengine_reset_sync_id(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_addressesbridgedengine_set_last_sync(`ptr`: Long,`lastSync`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_addressesbridgedengine_set_uploaded(`ptr`: Long,`newTimestamp`: Long,`uploadedIds`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_addressesbridgedengine_store_incoming(`ptr`: Long,`incomingEnvelopesAsJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_addressesbridgedengine_sync_finished(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_addressesbridgedengine_sync_id(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_addressesbridgedengine_sync_started(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_addressesbridgedengine_wipe(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_clone_store(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun uniffi_autofill_fn_free_store(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_constructor_store_new(`dbpath`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun uniffi_autofill_fn_method_store_add_address(`ptr`: Long,`a`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_add_address_with_meta(`ptr`: Long,`entryWithMeta`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_add_credit_card(`ptr`: Long,`cc`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_add_many_address_tombstones(`ptr`: Long,`tombstones`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_add_many_addresses_with_meta(`ptr`: Long,`entriesWithMeta`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_add_passport(`ptr`: Long,`p`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_addresses_bridged_engine(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun uniffi_autofill_fn_method_store_count_all_addresses(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun uniffi_autofill_fn_method_store_count_all_credit_cards(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun uniffi_autofill_fn_method_store_count_all_passports(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun uniffi_autofill_fn_method_store_delete_address(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Byte
external fun uniffi_autofill_fn_method_store_delete_all_addresses(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_delete_credit_card(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Byte
external fun uniffi_autofill_fn_method_store_delete_passport(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Byte
external fun uniffi_autofill_fn_method_store_get_address(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_get_all_addresses(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_get_all_credit_cards(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_get_all_passports(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_get_credit_card(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_get_passport(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_register_with_sync_manager(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_run_maintenance(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_scrub_encrypted_data(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_scrub_undecryptable_credit_card_data_for_remote_replacement(`ptr`: Long,`localEncryptionKey`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_method_store_shutdown(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_touch_address(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_touch_credit_card(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_touch_passport(`ptr`: Long,`guid`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_update_address(`ptr`: Long,`guid`: RustBuffer.ByValue,`a`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_update_address_with_meta(`ptr`: Long,`entryWithMeta`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_update_credit_card(`ptr`: Long,`guid`: RustBuffer.ByValue,`cc`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_method_store_update_passport(`ptr`: Long,`guid`: RustBuffer.ByValue,`p`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun uniffi_autofill_fn_func_create_autofill_key(uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_func_decrypt_string(`key`: RustBuffer.ByValue,`ciphertext`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun uniffi_autofill_fn_func_encrypt_string(`key`: RustBuffer.ByValue,`cleartext`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun ffi_autofill_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun ffi_autofill_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun ffi_autofill_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 
): Unit
external fun ffi_autofill_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun ffi_autofill_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_u8(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_u8(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Byte
external fun ffi_autofill_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_i8(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_i8(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Byte
external fun ffi_autofill_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_u16(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_u16(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Short
external fun ffi_autofill_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_i16(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_i16(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Short
external fun ffi_autofill_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_u32(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_u32(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Int
external fun ffi_autofill_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_i32(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_i32(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Int
external fun ffi_autofill_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_u64(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_u64(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun ffi_autofill_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_i64(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_i64(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Long
external fun ffi_autofill_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_f32(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_f32(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Float
external fun ffi_autofill_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_f64(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_f64(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Double
external fun ffi_autofill_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_rust_buffer(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_rust_buffer(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): RustBuffer.ByValue
external fun ffi_autofill_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_autofill_rust_future_cancel_void(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_free_void(`handle`: Long,
): Unit
external fun ffi_autofill_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 
): Unit

    
}

private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
    // Get the bindings contract version from our ComponentInterface
    val bindings_contract_version = 30
    // Get the scaffolding contract version by calling the into the dylib
    val scaffolding_contract_version = lib.ffi_autofill_uniffi_contract_version()
    if (bindings_contract_version != scaffolding_contract_version) {
        throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
    }
}

/**
 * @suppress
 */
public fun uniffiEnsureInitialized() {
    IntegrityCheckingUniffiLib
    // UniffiLib() initialized as objects are used, but we still need to explicitly
    // reference it so initialization across crates works as expected.
    UniffiLib
}

// Async support

// Public interface members begin here.


// Interface implemented by anything that can contain an object reference.
//
// Such types expose a `destroy()` method that must be called to cleanly
// dispose of the contained objects. Failure to call this method may result
// in memory leaks.
//
// The easiest way to ensure this method is called is to use the `.use`
// helper method to execute a block and destroy the object at the end.
interface Disposable {
    fun destroy()
    companion object {
        fun destroy(vararg args: Any?) {
            for (arg in args) {
                when (arg) {
                    is Disposable -> arg.destroy()
                    is ArrayList<*> -> {
                        for (idx in arg.indices) {
                            val element = arg[idx]
                            if (element is Disposable) {
                                element.destroy()
                            }
                        }
                    }
                    is Map<*, *> -> {
                        for (element in arg.values) {
                            if (element is Disposable) {
                                element.destroy()
                            }
                        }
                    }
                    is Iterable<*> -> {
                        for (element in arg) {
                            if (element is Disposable) {
                                element.destroy()
                            }
                        }
                    }
                }
            }
        }
    }
}

/**
 * @suppress
 */
inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
    try {
        block(this)
    } finally {
        try {
            // N.B. our implementation is on the nullable type `Disposable?`.
            this?.destroy()
        } catch (e: Throwable) {
            // swallow
        }
    }

/** 
 * Placeholder object used to signal that we're constructing an interface with a FFI handle.
 *
 * This is the first argument for interface constructors that input a raw handle. It exists is that
 * so we can avoid signature conflicts when an interface has a regular constructor than inputs a
 * Long.
 *
 * @suppress
 * */
object UniffiWithHandle

/** 
 * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
 *
 * @suppress
 * */
object NoHandle
/**
 * The cleaner interface for Object finalization code to run.
 * This is the entry point to any implementation that we're using.
 *
 * The cleaner registers objects and returns cleanables, so now we are
 * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
 * different implmentations available at compile time.
 *
 * @suppress
 */
interface UniffiCleaner {
    interface Cleanable {
        fun clean()
    }

    fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable

    companion object
}

// The fallback Jna cleaner, which is available for both Android, and the JVM.
private class UniffiJnaCleaner : UniffiCleaner {
    private val cleaner = com.sun.jna.internal.Cleaner.getCleaner()

    override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
        UniffiJnaCleanable(cleaner.register(value, cleanUpTask))
}

private class UniffiJnaCleanable(
    private val cleanable: com.sun.jna.internal.Cleaner.Cleanable,
) : UniffiCleaner.Cleanable {
    override fun clean() = cleanable.clean()
}


// We decide at uniffi binding generation time whether we were
// using Android or not.
// There are further runtime checks to chose the correct implementation
// of the cleaner.
private fun UniffiCleaner.Companion.create(): UniffiCleaner =
    try {
        // For safety's sake: if the library hasn't been run in android_cleaner = true
        // mode, but is being run on Android, then we still need to think about
        // Android API versions.
        // So we check if java.lang.ref.Cleaner is there, and use that…
        java.lang.Class.forName("java.lang.ref.Cleaner")
        JavaLangRefCleaner()
    } catch (e: ClassNotFoundException) {
        // … otherwise, fallback to the JNA cleaner.
        UniffiJnaCleaner()
    }

private class JavaLangRefCleaner : UniffiCleaner {
    val cleaner = java.lang.ref.Cleaner.create()

    override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
        JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
}

private class JavaLangRefCleanable(
    val cleanable: java.lang.ref.Cleaner.Cleanable
) : UniffiCleaner.Cleanable {
    override fun clean() = cleanable.clean()
}

/**
 * @suppress
 */
public object FfiConverterULong: FfiConverter<ULong, Long> {
    override fun lift(value: Long): ULong {
        return value.toULong()
    }

    override fun read(buf: ByteBuffer): ULong {
        return lift(buf.getLong())
    }

    override fun lower(value: ULong): Long {
        return value.toLong()
    }

    override fun allocationSize(value: ULong) = 8UL

    override fun write(value: ULong, buf: ByteBuffer) {
        buf.putLong(value.toLong())
    }
}

/**
 * @suppress
 */
public object FfiConverterLong: FfiConverter<Long, Long> {
    override fun lift(value: Long): Long {
        return value
    }

    override fun read(buf: ByteBuffer): Long {
        return buf.getLong()
    }

    override fun lower(value: Long): Long {
        return value
    }

    override fun allocationSize(value: Long) = 8UL

    override fun write(value: Long, buf: ByteBuffer) {
        buf.putLong(value)
    }
}

/**
 * @suppress
 */
public object FfiConverterBoolean: FfiConverter<Boolean, Byte> {
    override fun lift(value: Byte): Boolean {
        return value.toInt() != 0
    }

    override fun read(buf: ByteBuffer): Boolean {
        return lift(buf.get())
    }

    override fun lower(value: Boolean): Byte {
        return if (value) 1.toByte() else 0.toByte()
    }

    override fun allocationSize(value: Boolean) = 1UL

    override fun write(value: Boolean, buf: ByteBuffer) {
        buf.put(lower(value))
    }
}

/**
 * @suppress
 */
public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
    // Note: we don't inherit from FfiConverterRustBuffer, because we use a
    // special encoding when lowering/lifting.  We can use `RustBuffer.len` to
    // store our length and avoid writing it out to the buffer.
    override fun lift(value: RustBuffer.ByValue): String {
        try {
            val byteArr = ByteArray(value.len.toInt())
            value.asByteBuffer()!!.get(byteArr)
            return byteArr.toString(Charsets.UTF_8)
        } finally {
            RustBuffer.free(value)
        }
    }

    override fun read(buf: ByteBuffer): String {
        val len = buf.getInt()
        val byteArr = ByteArray(len)
        buf.get(byteArr)
        return byteArr.toString(Charsets.UTF_8)
    }

    fun toUtf8(value: String): ByteBuffer {
        // Make sure we don't have invalid UTF-16, check for lone surrogates.
        return Charsets.UTF_8.newEncoder().run {
            onMalformedInput(CodingErrorAction.REPORT)
            encode(CharBuffer.wrap(value))
        }
    }

    override fun lower(value: String): RustBuffer.ByValue {
        val byteBuf = toUtf8(value)
        // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
        // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
        val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
        rbuf.asByteBuffer()!!.put(byteBuf)
        return rbuf
    }

    // We aren't sure exactly how many bytes our string will be once it's UTF-8
    // encoded.  Allocate 3 bytes per UTF-16 code unit which will always be
    // enough.
    override fun allocationSize(value: String): ULong {
        val sizeForLength = 4UL
        val sizeForString = value.length.toULong() * 3UL
        return sizeForLength + sizeForString
    }

    override fun write(value: String, buf: ByteBuffer) {
        val byteBuf = toUtf8(value)
        buf.putInt(byteBuf.limit())
        buf.put(byteBuf)
    }
}


// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
//   * Each instance holds an opaque handle to the underlying Rust struct.
//     Method calls need to read this handle from the object's state and pass it in to
//     the Rust FFI.
//
//   * When an instance is no longer needed, its handle should be passed to a
//     special destructor function provided by the Rust FFI, which will drop the
//     underlying Rust struct.
//
//   * Given an instance, calling code is expected to call the special
//     `destroy` method in order to free it after use, either by calling it explicitly
//     or by using a higher-level helper like the `use` method. Failing to do so risks
//     leaking the underlying Rust struct.
//
//   * We can't assume that calling code will do the right thing, and must be prepared
//     to handle Kotlin method calls executing concurrently with or even after a call to
//     `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
//   * We must never allow Rust code to operate on the underlying Rust struct after
//     the destructor has been called, and must never call the destructor more than once.
//     Doing so may trigger memory unsafety.
//
//   * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
//     is implemented to call the destructor when the Kotlin object becomes unreachable.
//     This is done in a background thread. This is not a panacea, and client code should be aware that
//      1. the thread may starve if some there are objects that have poorly performing
//     `drop` methods or do significant work in their `drop` methods.
//      2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
//         or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
//    * Thread A starts a method call, reads the value of the handle, but is interrupted
//      before it can pass the handle over the FFI to Rust.
//    * Thread B calls `destroy` and frees the underlying Rust struct.
//    * Thread A resumes, passing the already-read handle value to Rust and triggering
//      a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
//    * The initial value of the counter is 1, indicating a live object with no in-flight calls.
//      The initial value for the flag is false.
//
//    * At the start of each method call, we atomically check the counter.
//      If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
//      If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
//    * At the end of each method call, we atomically decrement and check the counter.
//      If it has reached zero then we destroy the underlying Rust struct.
//
//    * When `destroy` is called, we atomically flip the flag from false to true.
//      If the flag was already true we silently fail.
//      Otherwise we atomically decrement and check the counter.
//      If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//


/**
 * The bridged sync engine for addresses. The canonical docs are in
 * services/interfaces/mozIBridgedSyncEngine.idl.
 * NOTE: all timestamps here are milliseconds.
 */
public interface AddressesBridgedEngineInterface {
    
    fun `apply`(): List<kotlin.String>
    
    fun `ensureCurrentSyncId`(`newSyncId`: kotlin.String): kotlin.String
    
    fun `lastSync`(): kotlin.Long
    
    fun `prepareForSync`(`clientData`: kotlin.String)
    
    fun `reset`()
    
    fun `resetSyncId`(): kotlin.String
    
    fun `setLastSync`(`lastSync`: kotlin.Long)
    
    fun `setUploaded`(`newTimestamp`: kotlin.Long, `uploadedIds`: List<kotlin.String>)
    
    fun `storeIncoming`(`incomingEnvelopesAsJson`: List<kotlin.String>)
    
    fun `syncFinished`()
    
    fun `syncId`(): kotlin.String?
    
    fun `syncStarted`()
    
    fun `wipe`()
    
    companion object
}

/**
 * The bridged sync engine for addresses. The canonical docs are in
 * services/interfaces/mozIBridgedSyncEngine.idl.
 * NOTE: all timestamps here are milliseconds.
 */
open class AddressesBridgedEngine: Disposable, AutoCloseable, AddressesBridgedEngineInterface
{

    @Suppress("UNUSED_PARAMETER")
    /**
     * @suppress
     */
    constructor(withHandle: UniffiWithHandle, handle: Long) {
        this.handle = handle
        this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
    }

    /**
     * @suppress
     *
     * This constructor can be used to instantiate a fake object. Only used for tests. Any
     * attempt to actually use an object constructed this way will fail as there is no
     * connected Rust object.
     */
    @Suppress("UNUSED_PARAMETER")
    constructor(noHandle: NoHandle) {
        this.handle = 0
        this.cleanable = null
    }

    protected val handle: Long
    protected val cleanable: UniffiCleaner.Cleanable?

    private val wasDestroyed = AtomicBoolean(false)
    private val callCounter = AtomicLong(1)

    override fun destroy() {
        // Only allow a single call to this method.
        // TODO: maybe we should log a warning if called more than once?
        if (this.wasDestroyed.compareAndSet(false, true)) {
            // This decrement always matches the initial count of 1 given at creation time.
            if (this.callCounter.decrementAndGet() == 0L) {
                cleanable?.clean()
            }
        }
    }

    @Synchronized
    override fun close() {
        this.destroy()
    }

    internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
        // Check and increment the call counter, to keep the object alive.
        // This needs a compare-and-set retry loop in case of concurrent updates.
        do {
            val c = this.callCounter.get()
            if (c == 0L) {
                throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
            }
            if (c == Long.MAX_VALUE) {
                throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
            }
        } while (! this.callCounter.compareAndSet(c, c + 1L))
        // Now we can safely do the method call without the handle being freed concurrently.
        try {
            return block(this.uniffiCloneHandle())
        } finally {
            // This decrement always matches the increment we performed above.
            if (this.callCounter.decrementAndGet() == 0L) {
                cleanable?.clean()
            }
        }
    }

    // Use a static inner class instead of a closure so as not to accidentally
    // capture `this` as part of the cleanable's action.
    private class UniffiCleanAction(private val handle: Long) : Runnable {
        override fun run() {
            if (handle == 0.toLong()) {
                // Fake object created with `NoHandle`, don't try to free.
                return;
            }
            uniffiRustCall { status ->
                UniffiLib.uniffi_autofill_fn_free_addressesbridgedengine(handle, status)
            }
        }
    }

    /**
     * @suppress
     */
    fun uniffiCloneHandle(): Long {
        if (handle == 0.toLong()) {
            throw InternalException("uniffiCloneHandle() called on NoHandle object");
        }
        return uniffiRustCall() { status ->
            UniffiLib.uniffi_autofill_fn_clone_addressesbridgedengine(handle, status)
        }
    }

    
    @Throws(AutofillApiException::class)override fun `apply`(): List<kotlin.String> {
            return FfiConverterSequenceString.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_apply(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `ensureCurrentSyncId`(`newSyncId`: kotlin.String): kotlin.String {
            return FfiConverterString.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_ensure_current_sync_id(
        it,
        FfiConverterString.lower(`newSyncId`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `lastSync`(): kotlin.Long {
            return FfiConverterLong.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_last_sync(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `prepareForSync`(`clientData`: kotlin.String)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_prepare_for_sync(
        it,
        FfiConverterString.lower(`clientData`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `reset`()
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_reset(
        it,
        _status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `resetSyncId`(): kotlin.String {
            return FfiConverterString.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_reset_sync_id(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `setLastSync`(`lastSync`: kotlin.Long)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_set_last_sync(
        it,
        FfiConverterLong.lower(`lastSync`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `setUploaded`(`newTimestamp`: kotlin.Long, `uploadedIds`: List<kotlin.String>)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_set_uploaded(
        it,
        FfiConverterLong.lower(`newTimestamp`),FfiConverterSequenceString.lower(`uploadedIds`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `storeIncoming`(`incomingEnvelopesAsJson`: List<kotlin.String>)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_store_incoming(
        it,
        FfiConverterSequenceString.lower(`incomingEnvelopesAsJson`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `syncFinished`()
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_sync_finished(
        it,
        _status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `syncId`(): kotlin.String? {
            return FfiConverterOptionalString.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_sync_id(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `syncStarted`()
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_sync_started(
        it,
        _status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `wipe`()
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_addressesbridgedengine_wipe(
        it,
        _status)
}
    }
    
    

    

    


    
    
    /**
     * @suppress
     */
    companion object
    
}


/**
 * @suppress
 */
public object FfiConverterTypeAddressesBridgedEngine: FfiConverter<AddressesBridgedEngine, Long> {
    override fun lower(value: AddressesBridgedEngine): Long {
        return value.uniffiCloneHandle()
    }

    override fun lift(value: Long): AddressesBridgedEngine {
        return AddressesBridgedEngine(UniffiWithHandle, value)
    }

    override fun read(buf: ByteBuffer): AddressesBridgedEngine {
        return lift(buf.getLong())
    }

    override fun allocationSize(value: AddressesBridgedEngine) = 8UL

    override fun write(value: AddressesBridgedEngine, buf: ByteBuffer) {
        buf.putLong(lower(value))
    }
}


// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
//   * Each instance holds an opaque handle to the underlying Rust struct.
//     Method calls need to read this handle from the object's state and pass it in to
//     the Rust FFI.
//
//   * When an instance is no longer needed, its handle should be passed to a
//     special destructor function provided by the Rust FFI, which will drop the
//     underlying Rust struct.
//
//   * Given an instance, calling code is expected to call the special
//     `destroy` method in order to free it after use, either by calling it explicitly
//     or by using a higher-level helper like the `use` method. Failing to do so risks
//     leaking the underlying Rust struct.
//
//   * We can't assume that calling code will do the right thing, and must be prepared
//     to handle Kotlin method calls executing concurrently with or even after a call to
//     `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
//   * We must never allow Rust code to operate on the underlying Rust struct after
//     the destructor has been called, and must never call the destructor more than once.
//     Doing so may trigger memory unsafety.
//
//   * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
//     is implemented to call the destructor when the Kotlin object becomes unreachable.
//     This is done in a background thread. This is not a panacea, and client code should be aware that
//      1. the thread may starve if some there are objects that have poorly performing
//     `drop` methods or do significant work in their `drop` methods.
//      2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
//         or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
//    * Thread A starts a method call, reads the value of the handle, but is interrupted
//      before it can pass the handle over the FFI to Rust.
//    * Thread B calls `destroy` and frees the underlying Rust struct.
//    * Thread A resumes, passing the already-read handle value to Rust and triggering
//      a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
//    * The initial value of the counter is 1, indicating a live object with no in-flight calls.
//      The initial value for the flag is false.
//
//    * At the start of each method call, we atomically check the counter.
//      If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
//      If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
//    * At the end of each method call, we atomically decrement and check the counter.
//      If it has reached zero then we destroy the underlying Rust struct.
//
//    * When `destroy` is called, we atomically flip the flag from false to true.
//      If the flag was already true we silently fail.
//      Otherwise we atomically decrement and check the counter.
//      If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//


public interface StoreInterface {
    
    fun `addAddress`(`a`: UpdatableAddressFields): Address
    
    fun `addAddressWithMeta`(`entryWithMeta`: UpdatableAddressFieldsWithMeta): Address
    
    fun `addCreditCard`(`cc`: UpdatableCreditCardFields): CreditCard
    
    fun `addManyAddressTombstones`(`tombstones`: List<AddressTombstone>): List<AddressBulkTombstoneResultEntry>
    
    fun `addManyAddressesWithMeta`(`entriesWithMeta`: List<UpdatableAddressFieldsWithMeta>): List<AddressBulkResultEntry>
    
    fun `addPassport`(`p`: UpdatablePassportFields): Passport
    
    /**
     * Returns a bridged sync engine for addresses, for use by Desktop's Sync
     * framework. Constructing it only assembles structs and never touches the
     * DB, so it cannot fail.
     */
    fun `addressesBridgedEngine`(): AddressesBridgedEngine
    
    fun `countAllAddresses`(): kotlin.Long
    
    fun `countAllCreditCards`(): kotlin.Long
    
    fun `countAllPassports`(): kotlin.Long
    
    fun `deleteAddress`(`guid`: kotlin.String): kotlin.Boolean
    
    /**
     * Removes every address and every address tombstone.
     */
    fun `deleteAllAddresses`()
    
    fun `deleteCreditCard`(`guid`: kotlin.String): kotlin.Boolean
    
    fun `deletePassport`(`guid`: kotlin.String): kotlin.Boolean
    
    fun `getAddress`(`guid`: kotlin.String): Address
    
    fun `getAllAddresses`(): List<Address>
    
    fun `getAllCreditCards`(): List<CreditCard>
    
    fun `getAllPassports`(): List<Passport>
    
    fun `getCreditCard`(`guid`: kotlin.String): CreditCard
    
    fun `getPassport`(`guid`: kotlin.String): Passport
    
    fun `registerWithSyncManager`()
    
    /**
     * Run maintenance on the DB
     *
     * This is intended to be run during idle time and will take steps / to clean up / shrink the
     * database.
     */
    fun `runMaintenance`()
    
    fun `scrubEncryptedData`()
    
    /**
     * The `scrub_undecryptable_credit_card_data_for_remote_replacement` function locally scrubs credit cards
     * that cannot be decrypted, sets the record's metadata to their default values, and resets the credit card
     * engine so any existing server records can overwrite the locally scrubbed records.
     *
     * NB: This function was created to unblock iOS credit card users who are unable to sync records and should not be used
     * outside of this use case.
     */
    fun `scrubUndecryptableCreditCardDataForRemoteReplacement`(`localEncryptionKey`: kotlin.String): CreditCardsDeletionMetrics
    
    fun `shutdown`()
    
    fun `touchAddress`(`guid`: kotlin.String)
    
    fun `touchCreditCard`(`guid`: kotlin.String)
    
    fun `touchPassport`(`guid`: kotlin.String)
    
    fun `updateAddress`(`guid`: kotlin.String, `a`: UpdatableAddressFields)
    
    fun `updateAddressWithMeta`(`entryWithMeta`: UpdatableAddressFieldsWithMeta)
    
    fun `updateCreditCard`(`guid`: kotlin.String, `cc`: UpdatableCreditCardFields)
    
    fun `updatePassport`(`guid`: kotlin.String, `p`: UpdatablePassportFields)
    
    companion object
}

open class Store: Disposable, AutoCloseable, StoreInterface
{

    @Suppress("UNUSED_PARAMETER")
    /**
     * @suppress
     */
    constructor(withHandle: UniffiWithHandle, handle: Long) {
        this.handle = handle
        this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
    }

    /**
     * @suppress
     *
     * This constructor can be used to instantiate a fake object. Only used for tests. Any
     * attempt to actually use an object constructed this way will fail as there is no
     * connected Rust object.
     */
    @Suppress("UNUSED_PARAMETER")
    constructor(noHandle: NoHandle) {
        this.handle = 0
        this.cleanable = null
    }
    constructor(`dbpath`: kotlin.String) :
        this(UniffiWithHandle, 
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_constructor_store_new(
    
        FfiConverterString.lower(`dbpath`),_status)
}
    )

    protected val handle: Long
    protected val cleanable: UniffiCleaner.Cleanable?

    private val wasDestroyed = AtomicBoolean(false)
    private val callCounter = AtomicLong(1)

    override fun destroy() {
        // Only allow a single call to this method.
        // TODO: maybe we should log a warning if called more than once?
        if (this.wasDestroyed.compareAndSet(false, true)) {
            // This decrement always matches the initial count of 1 given at creation time.
            if (this.callCounter.decrementAndGet() == 0L) {
                cleanable?.clean()
            }
        }
    }

    @Synchronized
    override fun close() {
        this.destroy()
    }

    internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
        // Check and increment the call counter, to keep the object alive.
        // This needs a compare-and-set retry loop in case of concurrent updates.
        do {
            val c = this.callCounter.get()
            if (c == 0L) {
                throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
            }
            if (c == Long.MAX_VALUE) {
                throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
            }
        } while (! this.callCounter.compareAndSet(c, c + 1L))
        // Now we can safely do the method call without the handle being freed concurrently.
        try {
            return block(this.uniffiCloneHandle())
        } finally {
            // This decrement always matches the increment we performed above.
            if (this.callCounter.decrementAndGet() == 0L) {
                cleanable?.clean()
            }
        }
    }

    // Use a static inner class instead of a closure so as not to accidentally
    // capture `this` as part of the cleanable's action.
    private class UniffiCleanAction(private val handle: Long) : Runnable {
        override fun run() {
            if (handle == 0.toLong()) {
                // Fake object created with `NoHandle`, don't try to free.
                return;
            }
            uniffiRustCall { status ->
                UniffiLib.uniffi_autofill_fn_free_store(handle, status)
            }
        }
    }

    /**
     * @suppress
     */
    fun uniffiCloneHandle(): Long {
        if (handle == 0.toLong()) {
            throw InternalException("uniffiCloneHandle() called on NoHandle object");
        }
        return uniffiRustCall() { status ->
            UniffiLib.uniffi_autofill_fn_clone_store(handle, status)
        }
    }

    
    @Throws(AutofillApiException::class)override fun `addAddress`(`a`: UpdatableAddressFields): Address {
            return FfiConverterTypeAddress.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_add_address(
        it,
        FfiConverterTypeUpdatableAddressFields.lower(`a`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `addAddressWithMeta`(`entryWithMeta`: UpdatableAddressFieldsWithMeta): Address {
            return FfiConverterTypeAddress.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_add_address_with_meta(
        it,
        FfiConverterTypeUpdatableAddressFieldsWithMeta.lower(`entryWithMeta`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `addCreditCard`(`cc`: UpdatableCreditCardFields): CreditCard {
            return FfiConverterTypeCreditCard.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_add_credit_card(
        it,
        FfiConverterTypeUpdatableCreditCardFields.lower(`cc`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `addManyAddressTombstones`(`tombstones`: List<AddressTombstone>): List<AddressBulkTombstoneResultEntry> {
            return FfiConverterSequenceTypeAddressBulkTombstoneResultEntry.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_add_many_address_tombstones(
        it,
        FfiConverterSequenceTypeAddressTombstone.lower(`tombstones`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `addManyAddressesWithMeta`(`entriesWithMeta`: List<UpdatableAddressFieldsWithMeta>): List<AddressBulkResultEntry> {
            return FfiConverterSequenceTypeAddressBulkResultEntry.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_add_many_addresses_with_meta(
        it,
        FfiConverterSequenceTypeUpdatableAddressFieldsWithMeta.lower(`entriesWithMeta`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `addPassport`(`p`: UpdatablePassportFields): Passport {
            return FfiConverterTypePassport.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_add_passport(
        it,
        FfiConverterTypeUpdatablePassportFields.lower(`p`),_status)
}
    }
    )
    }
    

    
    /**
     * Returns a bridged sync engine for addresses, for use by Desktop's Sync
     * framework. Constructing it only assembles structs and never touches the
     * DB, so it cannot fail.
     */override fun `addressesBridgedEngine`(): AddressesBridgedEngine {
            return FfiConverterTypeAddressesBridgedEngine.lift(
    callWithHandle {
    uniffiRustCall() { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_addresses_bridged_engine(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `countAllAddresses`(): kotlin.Long {
            return FfiConverterLong.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_count_all_addresses(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `countAllCreditCards`(): kotlin.Long {
            return FfiConverterLong.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_count_all_credit_cards(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `countAllPassports`(): kotlin.Long {
            return FfiConverterLong.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_count_all_passports(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `deleteAddress`(`guid`: kotlin.String): kotlin.Boolean {
            return FfiConverterBoolean.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_delete_address(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    )
    }
    

    
    /**
     * Removes every address and every address tombstone.
     */
    @Throws(AutofillApiException::class)override fun `deleteAllAddresses`()
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_delete_all_addresses(
        it,
        _status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `deleteCreditCard`(`guid`: kotlin.String): kotlin.Boolean {
            return FfiConverterBoolean.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_delete_credit_card(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `deletePassport`(`guid`: kotlin.String): kotlin.Boolean {
            return FfiConverterBoolean.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_delete_passport(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `getAddress`(`guid`: kotlin.String): Address {
            return FfiConverterTypeAddress.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_get_address(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `getAllAddresses`(): List<Address> {
            return FfiConverterSequenceTypeAddress.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_get_all_addresses(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `getAllCreditCards`(): List<CreditCard> {
            return FfiConverterSequenceTypeCreditCard.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_get_all_credit_cards(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `getAllPassports`(): List<Passport> {
            return FfiConverterSequenceTypePassport.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_get_all_passports(
        it,
        _status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `getCreditCard`(`guid`: kotlin.String): CreditCard {
            return FfiConverterTypeCreditCard.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_get_credit_card(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    )
    }
    

    
    @Throws(AutofillApiException::class)override fun `getPassport`(`guid`: kotlin.String): Passport {
            return FfiConverterTypePassport.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_get_passport(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    )
    }
    

    override fun `registerWithSyncManager`()
        = 
    callWithHandle {
    uniffiRustCall() { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_register_with_sync_manager(
        it,
        _status)
}
    }
    
    

    
    /**
     * Run maintenance on the DB
     *
     * This is intended to be run during idle time and will take steps / to clean up / shrink the
     * database.
     */
    @Throws(AutofillApiException::class)override fun `runMaintenance`()
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_run_maintenance(
        it,
        _status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `scrubEncryptedData`()
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_scrub_encrypted_data(
        it,
        _status)
}
    }
    
    

    
    /**
     * The `scrub_undecryptable_credit_card_data_for_remote_replacement` function locally scrubs credit cards
     * that cannot be decrypted, sets the record's metadata to their default values, and resets the credit card
     * engine so any existing server records can overwrite the locally scrubbed records.
     *
     * NB: This function was created to unblock iOS credit card users who are unable to sync records and should not be used
     * outside of this use case.
     */
    @Throws(AutofillApiException::class)override fun `scrubUndecryptableCreditCardDataForRemoteReplacement`(`localEncryptionKey`: kotlin.String): CreditCardsDeletionMetrics {
            return FfiConverterTypeCreditCardsDeletionMetrics.lift(
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_scrub_undecryptable_credit_card_data_for_remote_replacement(
        it,
        FfiConverterString.lower(`localEncryptionKey`),_status)
}
    }
    )
    }
    

    override fun `shutdown`()
        = 
    callWithHandle {
    uniffiRustCall() { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_shutdown(
        it,
        _status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `touchAddress`(`guid`: kotlin.String)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_touch_address(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `touchCreditCard`(`guid`: kotlin.String)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_touch_credit_card(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `touchPassport`(`guid`: kotlin.String)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_touch_passport(
        it,
        FfiConverterString.lower(`guid`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `updateAddress`(`guid`: kotlin.String, `a`: UpdatableAddressFields)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_update_address(
        it,
        FfiConverterString.lower(`guid`),FfiConverterTypeUpdatableAddressFields.lower(`a`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `updateAddressWithMeta`(`entryWithMeta`: UpdatableAddressFieldsWithMeta)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_update_address_with_meta(
        it,
        FfiConverterTypeUpdatableAddressFieldsWithMeta.lower(`entryWithMeta`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `updateCreditCard`(`guid`: kotlin.String, `cc`: UpdatableCreditCardFields)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_update_credit_card(
        it,
        FfiConverterString.lower(`guid`),FfiConverterTypeUpdatableCreditCardFields.lower(`cc`),_status)
}
    }
    
    

    
    @Throws(AutofillApiException::class)override fun `updatePassport`(`guid`: kotlin.String, `p`: UpdatablePassportFields)
        = 
    callWithHandle {
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_method_store_update_passport(
        it,
        FfiConverterString.lower(`guid`),FfiConverterTypeUpdatablePassportFields.lower(`p`),_status)
}
    }
    
    

    

    


    
    
    /**
     * @suppress
     */
    companion object
    
}


/**
 * @suppress
 */
public object FfiConverterTypeStore: FfiConverter<Store, Long> {
    override fun lower(value: Store): Long {
        return value.uniffiCloneHandle()
    }

    override fun lift(value: Long): Store {
        return Store(UniffiWithHandle, value)
    }

    override fun read(buf: ByteBuffer): Store {
        return lift(buf.getLong())
    }

    override fun allocationSize(value: Store) = 8UL

    override fun write(value: Store, buf: ByteBuffer) {
        buf.putLong(lower(value))
    }
}



/**
 * What you get back as an address.
 */
data class Address (
    var `guid`: kotlin.String
    , 
    var `name`: kotlin.String
    , 
    var `organization`: kotlin.String
    , 
    var `streetAddress`: kotlin.String
    , 
    var `addressLevel3`: kotlin.String
    , 
    var `addressLevel2`: kotlin.String
    , 
    var `addressLevel1`: kotlin.String
    , 
    var `postalCode`: kotlin.String
    , 
    var `country`: kotlin.String
    , 
    var `tel`: kotlin.String
    , 
    var `email`: kotlin.String
    , 
    var `timeCreated`: kotlin.Long
    , 
    var `timeLastUsed`: kotlin.Long?
    , 
    var `timeLastModified`: kotlin.Long
    , 
    var `timesUsed`: kotlin.Long
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeAddress: FfiConverterRustBuffer<Address> {
    override fun read(buf: ByteBuffer): Address {
        return Address(
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterOptionalLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
        )
    }

    override fun allocationSize(value: Address) = (
            FfiConverterString.allocationSize(value.`guid`) +
            FfiConverterString.allocationSize(value.`name`) +
            FfiConverterString.allocationSize(value.`organization`) +
            FfiConverterString.allocationSize(value.`streetAddress`) +
            FfiConverterString.allocationSize(value.`addressLevel3`) +
            FfiConverterString.allocationSize(value.`addressLevel2`) +
            FfiConverterString.allocationSize(value.`addressLevel1`) +
            FfiConverterString.allocationSize(value.`postalCode`) +
            FfiConverterString.allocationSize(value.`country`) +
            FfiConverterString.allocationSize(value.`tel`) +
            FfiConverterString.allocationSize(value.`email`) +
            FfiConverterLong.allocationSize(value.`timeCreated`) +
            FfiConverterOptionalLong.allocationSize(value.`timeLastUsed`) +
            FfiConverterLong.allocationSize(value.`timeLastModified`) +
            FfiConverterLong.allocationSize(value.`timesUsed`)
    )

    override fun write(value: Address, buf: ByteBuffer) {
            FfiConverterString.write(value.`guid`, buf)
            FfiConverterString.write(value.`name`, buf)
            FfiConverterString.write(value.`organization`, buf)
            FfiConverterString.write(value.`streetAddress`, buf)
            FfiConverterString.write(value.`addressLevel3`, buf)
            FfiConverterString.write(value.`addressLevel2`, buf)
            FfiConverterString.write(value.`addressLevel1`, buf)
            FfiConverterString.write(value.`postalCode`, buf)
            FfiConverterString.write(value.`country`, buf)
            FfiConverterString.write(value.`tel`, buf)
            FfiConverterString.write(value.`email`, buf)
            FfiConverterLong.write(value.`timeCreated`, buf)
            FfiConverterOptionalLong.write(value.`timeLastUsed`, buf)
            FfiConverterLong.write(value.`timeLastModified`, buf)
            FfiConverterLong.write(value.`timesUsed`, buf)
    }
}



/**
 * Metadata fields managed internally by the library: the guid, timestamps and
 * local sync state. These are automatically set on `add_address` and updated on
 * operations like `touch` and `update_address`. Not included in
 * `UpdatableAddressFields`; use `add_address_with_meta` when importing records
 * that already have metadata.
 */
data class AddressMeta (
    var `guid`: kotlin.String
    , 
    var `timeCreated`: kotlin.Long
    , 
    var `timeLastUsed`: kotlin.Long?
    , 
    var `timeLastModified`: kotlin.Long
    , 
    var `timesUsed`: kotlin.Long
    , 
    var `syncChangeCounter`: kotlin.Long
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeAddressMeta: FfiConverterRustBuffer<AddressMeta> {
    override fun read(buf: ByteBuffer): AddressMeta {
        return AddressMeta(
            FfiConverterString.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterOptionalLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
        )
    }

    override fun allocationSize(value: AddressMeta) = (
            FfiConverterString.allocationSize(value.`guid`) +
            FfiConverterLong.allocationSize(value.`timeCreated`) +
            FfiConverterOptionalLong.allocationSize(value.`timeLastUsed`) +
            FfiConverterLong.allocationSize(value.`timeLastModified`) +
            FfiConverterLong.allocationSize(value.`timesUsed`) +
            FfiConverterLong.allocationSize(value.`syncChangeCounter`)
    )

    override fun write(value: AddressMeta, buf: ByteBuffer) {
            FfiConverterString.write(value.`guid`, buf)
            FfiConverterLong.write(value.`timeCreated`, buf)
            FfiConverterOptionalLong.write(value.`timeLastUsed`, buf)
            FfiConverterLong.write(value.`timeLastModified`, buf)
            FfiConverterLong.write(value.`timesUsed`, buf)
            FfiConverterLong.write(value.`syncChangeCounter`, buf)
    }
}



/**
 * A tombstone for a record deleted locally but not yet uploaded, supplied to
 * `add_many_address_tombstones` when migrating from another store.
 */
data class AddressTombstone (
    var `guid`: kotlin.String
    , 
    var `timeDeleted`: kotlin.Long
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeAddressTombstone: FfiConverterRustBuffer<AddressTombstone> {
    override fun read(buf: ByteBuffer): AddressTombstone {
        return AddressTombstone(
            FfiConverterString.read(buf),
            FfiConverterLong.read(buf),
        )
    }

    override fun allocationSize(value: AddressTombstone) = (
            FfiConverterString.allocationSize(value.`guid`) +
            FfiConverterLong.allocationSize(value.`timeDeleted`)
    )

    override fun write(value: AddressTombstone, buf: ByteBuffer) {
            FfiConverterString.write(value.`guid`, buf)
            FfiConverterLong.write(value.`timeDeleted`, buf)
    }
}



/**
 * What you get back as a credit-card.
 */
data class CreditCard (
    var `guid`: kotlin.String
    , 
    var `ccName`: kotlin.String
    , 
    var `ccNumberEnc`: kotlin.String
    , 
    var `ccNumberLast4`: kotlin.String
    , 
    var `ccExpMonth`: kotlin.Long
    , 
    var `ccExpYear`: kotlin.Long
    , 
    var `ccType`: kotlin.String
    , 
    var `timeCreated`: kotlin.Long
    , 
    var `timeLastUsed`: kotlin.Long?
    , 
    var `timeLastModified`: kotlin.Long
    , 
    var `timesUsed`: kotlin.Long
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeCreditCard: FfiConverterRustBuffer<CreditCard> {
    override fun read(buf: ByteBuffer): CreditCard {
        return CreditCard(
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterString.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterOptionalLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
        )
    }

    override fun allocationSize(value: CreditCard) = (
            FfiConverterString.allocationSize(value.`guid`) +
            FfiConverterString.allocationSize(value.`ccName`) +
            FfiConverterString.allocationSize(value.`ccNumberEnc`) +
            FfiConverterString.allocationSize(value.`ccNumberLast4`) +
            FfiConverterLong.allocationSize(value.`ccExpMonth`) +
            FfiConverterLong.allocationSize(value.`ccExpYear`) +
            FfiConverterString.allocationSize(value.`ccType`) +
            FfiConverterLong.allocationSize(value.`timeCreated`) +
            FfiConverterOptionalLong.allocationSize(value.`timeLastUsed`) +
            FfiConverterLong.allocationSize(value.`timeLastModified`) +
            FfiConverterLong.allocationSize(value.`timesUsed`)
    )

    override fun write(value: CreditCard, buf: ByteBuffer) {
            FfiConverterString.write(value.`guid`, buf)
            FfiConverterString.write(value.`ccName`, buf)
            FfiConverterString.write(value.`ccNumberEnc`, buf)
            FfiConverterString.write(value.`ccNumberLast4`, buf)
            FfiConverterLong.write(value.`ccExpMonth`, buf)
            FfiConverterLong.write(value.`ccExpYear`, buf)
            FfiConverterString.write(value.`ccType`, buf)
            FfiConverterLong.write(value.`timeCreated`, buf)
            FfiConverterOptionalLong.write(value.`timeLastUsed`, buf)
            FfiConverterLong.write(value.`timeLastModified`, buf)
            FfiConverterLong.write(value.`timesUsed`, buf)
    }
}



/**
 * Metrics tracking scrubbing of credit cards that cannot be decrypted, see
 */
data class CreditCardsDeletionMetrics (
    var `totalScrubbedRecords`: kotlin.ULong
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeCreditCardsDeletionMetrics: FfiConverterRustBuffer<CreditCardsDeletionMetrics> {
    override fun read(buf: ByteBuffer): CreditCardsDeletionMetrics {
        return CreditCardsDeletionMetrics(
            FfiConverterULong.read(buf),
        )
    }

    override fun allocationSize(value: CreditCardsDeletionMetrics) = (
            FfiConverterULong.allocationSize(value.`totalScrubbedRecords`)
    )

    override fun write(value: CreditCardsDeletionMetrics, buf: ByteBuffer) {
            FfiConverterULong.write(value.`totalScrubbedRecords`, buf)
    }
}



/**
 * What you get back as a passport.
 */
data class Passport (
    var `guid`: kotlin.String
    , 
    var `name`: kotlin.String
    , 
    var `country`: kotlin.String
    , 
    var `passportNumber`: kotlin.String
    , 
    var `issueDateMonth`: kotlin.Long
    , 
    var `issueDateDay`: kotlin.Long
    , 
    var `issueDateYear`: kotlin.Long
    , 
    var `expiryDateMonth`: kotlin.Long
    , 
    var `expiryDateDay`: kotlin.Long
    , 
    var `expiryDateYear`: kotlin.Long
    , 
    var `timeCreated`: kotlin.Long
    , 
    var `timeLastUsed`: kotlin.Long?
    , 
    var `timeLastModified`: kotlin.Long
    , 
    var `timesUsed`: kotlin.Long
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypePassport: FfiConverterRustBuffer<Passport> {
    override fun read(buf: ByteBuffer): Passport {
        return Passport(
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterOptionalLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
        )
    }

    override fun allocationSize(value: Passport) = (
            FfiConverterString.allocationSize(value.`guid`) +
            FfiConverterString.allocationSize(value.`name`) +
            FfiConverterString.allocationSize(value.`country`) +
            FfiConverterString.allocationSize(value.`passportNumber`) +
            FfiConverterLong.allocationSize(value.`issueDateMonth`) +
            FfiConverterLong.allocationSize(value.`issueDateDay`) +
            FfiConverterLong.allocationSize(value.`issueDateYear`) +
            FfiConverterLong.allocationSize(value.`expiryDateMonth`) +
            FfiConverterLong.allocationSize(value.`expiryDateDay`) +
            FfiConverterLong.allocationSize(value.`expiryDateYear`) +
            FfiConverterLong.allocationSize(value.`timeCreated`) +
            FfiConverterOptionalLong.allocationSize(value.`timeLastUsed`) +
            FfiConverterLong.allocationSize(value.`timeLastModified`) +
            FfiConverterLong.allocationSize(value.`timesUsed`)
    )

    override fun write(value: Passport, buf: ByteBuffer) {
            FfiConverterString.write(value.`guid`, buf)
            FfiConverterString.write(value.`name`, buf)
            FfiConverterString.write(value.`country`, buf)
            FfiConverterString.write(value.`passportNumber`, buf)
            FfiConverterLong.write(value.`issueDateMonth`, buf)
            FfiConverterLong.write(value.`issueDateDay`, buf)
            FfiConverterLong.write(value.`issueDateYear`, buf)
            FfiConverterLong.write(value.`expiryDateMonth`, buf)
            FfiConverterLong.write(value.`expiryDateDay`, buf)
            FfiConverterLong.write(value.`expiryDateYear`, buf)
            FfiConverterLong.write(value.`timeCreated`, buf)
            FfiConverterOptionalLong.write(value.`timeLastUsed`, buf)
            FfiConverterLong.write(value.`timeLastModified`, buf)
            FfiConverterLong.write(value.`timesUsed`, buf)
    }
}



/**
 * What you pass to create or update an address.
 */
data class UpdatableAddressFields (
    var `name`: kotlin.String
    , 
    var `organization`: kotlin.String
    , 
    var `streetAddress`: kotlin.String
    , 
    var `addressLevel3`: kotlin.String
    , 
    var `addressLevel2`: kotlin.String
    , 
    var `addressLevel1`: kotlin.String
    , 
    var `postalCode`: kotlin.String
    , 
    var `country`: kotlin.String
    , 
    var `tel`: kotlin.String
    , 
    var `email`: kotlin.String
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeUpdatableAddressFields: FfiConverterRustBuffer<UpdatableAddressFields> {
    override fun read(buf: ByteBuffer): UpdatableAddressFields {
        return UpdatableAddressFields(
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
        )
    }

    override fun allocationSize(value: UpdatableAddressFields) = (
            FfiConverterString.allocationSize(value.`name`) +
            FfiConverterString.allocationSize(value.`organization`) +
            FfiConverterString.allocationSize(value.`streetAddress`) +
            FfiConverterString.allocationSize(value.`addressLevel3`) +
            FfiConverterString.allocationSize(value.`addressLevel2`) +
            FfiConverterString.allocationSize(value.`addressLevel1`) +
            FfiConverterString.allocationSize(value.`postalCode`) +
            FfiConverterString.allocationSize(value.`country`) +
            FfiConverterString.allocationSize(value.`tel`) +
            FfiConverterString.allocationSize(value.`email`)
    )

    override fun write(value: UpdatableAddressFields, buf: ByteBuffer) {
            FfiConverterString.write(value.`name`, buf)
            FfiConverterString.write(value.`organization`, buf)
            FfiConverterString.write(value.`streetAddress`, buf)
            FfiConverterString.write(value.`addressLevel3`, buf)
            FfiConverterString.write(value.`addressLevel2`, buf)
            FfiConverterString.write(value.`addressLevel1`, buf)
            FfiConverterString.write(value.`postalCode`, buf)
            FfiConverterString.write(value.`country`, buf)
            FfiConverterString.write(value.`tel`, buf)
            FfiConverterString.write(value.`email`, buf)
    }
}



/**
 * An address together with its metadata, passed to `add_address_with_meta` and
 * `update_address_with_meta` when importing a record from another store.
 */
data class UpdatableAddressFieldsWithMeta (
    var `fields`: UpdatableAddressFields
    , 
    var `meta`: AddressMeta
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeUpdatableAddressFieldsWithMeta: FfiConverterRustBuffer<UpdatableAddressFieldsWithMeta> {
    override fun read(buf: ByteBuffer): UpdatableAddressFieldsWithMeta {
        return UpdatableAddressFieldsWithMeta(
            FfiConverterTypeUpdatableAddressFields.read(buf),
            FfiConverterTypeAddressMeta.read(buf),
        )
    }

    override fun allocationSize(value: UpdatableAddressFieldsWithMeta) = (
            FfiConverterTypeUpdatableAddressFields.allocationSize(value.`fields`) +
            FfiConverterTypeAddressMeta.allocationSize(value.`meta`)
    )

    override fun write(value: UpdatableAddressFieldsWithMeta, buf: ByteBuffer) {
            FfiConverterTypeUpdatableAddressFields.write(value.`fields`, buf)
            FfiConverterTypeAddressMeta.write(value.`meta`, buf)
    }
}



/**
 * What you pass to create or update a credit-card.
 */
data class UpdatableCreditCardFields (
    var `ccName`: kotlin.String
    , 
    var `ccNumberEnc`: kotlin.String
    , 
    var `ccNumberLast4`: kotlin.String
    , 
    var `ccExpMonth`: kotlin.Long
    , 
    var `ccExpYear`: kotlin.Long
    , 
    var `ccType`: kotlin.String
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeUpdatableCreditCardFields: FfiConverterRustBuffer<UpdatableCreditCardFields> {
    override fun read(buf: ByteBuffer): UpdatableCreditCardFields {
        return UpdatableCreditCardFields(
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterString.read(buf),
        )
    }

    override fun allocationSize(value: UpdatableCreditCardFields) = (
            FfiConverterString.allocationSize(value.`ccName`) +
            FfiConverterString.allocationSize(value.`ccNumberEnc`) +
            FfiConverterString.allocationSize(value.`ccNumberLast4`) +
            FfiConverterLong.allocationSize(value.`ccExpMonth`) +
            FfiConverterLong.allocationSize(value.`ccExpYear`) +
            FfiConverterString.allocationSize(value.`ccType`)
    )

    override fun write(value: UpdatableCreditCardFields, buf: ByteBuffer) {
            FfiConverterString.write(value.`ccName`, buf)
            FfiConverterString.write(value.`ccNumberEnc`, buf)
            FfiConverterString.write(value.`ccNumberLast4`, buf)
            FfiConverterLong.write(value.`ccExpMonth`, buf)
            FfiConverterLong.write(value.`ccExpYear`, buf)
            FfiConverterString.write(value.`ccType`, buf)
    }
}



/**
 * What you pass to create or update a passport.
 */
data class UpdatablePassportFields (
    var `name`: kotlin.String
    , 
    var `country`: kotlin.String
    , 
    var `passportNumber`: kotlin.String
    , 
    var `issueDateMonth`: kotlin.Long
    , 
    var `issueDateDay`: kotlin.Long
    , 
    var `issueDateYear`: kotlin.Long
    , 
    var `expiryDateMonth`: kotlin.Long
    , 
    var `expiryDateDay`: kotlin.Long
    , 
    var `expiryDateYear`: kotlin.Long
    
){
    

    

    
    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeUpdatablePassportFields: FfiConverterRustBuffer<UpdatablePassportFields> {
    override fun read(buf: ByteBuffer): UpdatablePassportFields {
        return UpdatablePassportFields(
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterString.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
            FfiConverterLong.read(buf),
        )
    }

    override fun allocationSize(value: UpdatablePassportFields) = (
            FfiConverterString.allocationSize(value.`name`) +
            FfiConverterString.allocationSize(value.`country`) +
            FfiConverterString.allocationSize(value.`passportNumber`) +
            FfiConverterLong.allocationSize(value.`issueDateMonth`) +
            FfiConverterLong.allocationSize(value.`issueDateDay`) +
            FfiConverterLong.allocationSize(value.`issueDateYear`) +
            FfiConverterLong.allocationSize(value.`expiryDateMonth`) +
            FfiConverterLong.allocationSize(value.`expiryDateDay`) +
            FfiConverterLong.allocationSize(value.`expiryDateYear`)
    )

    override fun write(value: UpdatablePassportFields, buf: ByteBuffer) {
            FfiConverterString.write(value.`name`, buf)
            FfiConverterString.write(value.`country`, buf)
            FfiConverterString.write(value.`passportNumber`, buf)
            FfiConverterLong.write(value.`issueDateMonth`, buf)
            FfiConverterLong.write(value.`issueDateDay`, buf)
            FfiConverterLong.write(value.`issueDateYear`, buf)
            FfiConverterLong.write(value.`expiryDateMonth`, buf)
            FfiConverterLong.write(value.`expiryDateDay`, buf)
            FfiConverterLong.write(value.`expiryDateYear`, buf)
    }
}



/**
 * A bulk insert result entry, returned per input record by `add_many_addresses_with_meta`
 */
sealed class AddressBulkResultEntry {
    
    data class Success(
        val `address`: mozilla.appservices.autofill.Address) : AddressBulkResultEntry()
        
    {
        

        companion object
    }
    
    data class Error(
        val `message`: kotlin.String) : AddressBulkResultEntry()
        
    {
        

        companion object
    }
    

    

    
    


    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeAddressBulkResultEntry : FfiConverterRustBuffer<AddressBulkResultEntry>{
    override fun read(buf: ByteBuffer): AddressBulkResultEntry {
        return when(buf.getInt()) {
            1 -> AddressBulkResultEntry.Success(
                FfiConverterTypeAddress.read(buf),
                )
            2 -> AddressBulkResultEntry.Error(
                FfiConverterString.read(buf),
                )
            else -> throw RuntimeException("invalid enum value, something is very wrong!!")
        }
    }

    override fun allocationSize(value: AddressBulkResultEntry) = when(value) {
        is AddressBulkResultEntry.Success -> {
            // Add the size for the Int that specifies the variant plus the size needed for all fields
            (
                4UL
                + FfiConverterTypeAddress.allocationSize(value.`address`)
            )
        }
        is AddressBulkResultEntry.Error -> {
            // Add the size for the Int that specifies the variant plus the size needed for all fields
            (
                4UL
                + FfiConverterString.allocationSize(value.`message`)
            )
        }
    }

    override fun write(value: AddressBulkResultEntry, buf: ByteBuffer) {
        when(value) {
            is AddressBulkResultEntry.Success -> {
                buf.putInt(1)
                FfiConverterTypeAddress.write(value.`address`, buf)
                Unit
            }
            is AddressBulkResultEntry.Error -> {
                buf.putInt(2)
                FfiConverterString.write(value.`message`, buf)
                Unit
            }
        }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
    }
}





/**
 * Per-record result of `add_many_address_tombstones`.
 */
sealed class AddressBulkTombstoneResultEntry {
    
    data class Success(
        val `guid`: kotlin.String) : AddressBulkTombstoneResultEntry()
        
    {
        

        companion object
    }
    
    data class Error(
        val `message`: kotlin.String) : AddressBulkTombstoneResultEntry()
        
    {
        

        companion object
    }
    

    

    
    


    companion object
}

/**
 * @suppress
 */
public object FfiConverterTypeAddressBulkTombstoneResultEntry : FfiConverterRustBuffer<AddressBulkTombstoneResultEntry>{
    override fun read(buf: ByteBuffer): AddressBulkTombstoneResultEntry {
        return when(buf.getInt()) {
            1 -> AddressBulkTombstoneResultEntry.Success(
                FfiConverterString.read(buf),
                )
            2 -> AddressBulkTombstoneResultEntry.Error(
                FfiConverterString.read(buf),
                )
            else -> throw RuntimeException("invalid enum value, something is very wrong!!")
        }
    }

    override fun allocationSize(value: AddressBulkTombstoneResultEntry) = when(value) {
        is AddressBulkTombstoneResultEntry.Success -> {
            // Add the size for the Int that specifies the variant plus the size needed for all fields
            (
                4UL
                + FfiConverterString.allocationSize(value.`guid`)
            )
        }
        is AddressBulkTombstoneResultEntry.Error -> {
            // Add the size for the Int that specifies the variant plus the size needed for all fields
            (
                4UL
                + FfiConverterString.allocationSize(value.`message`)
            )
        }
    }

    override fun write(value: AddressBulkTombstoneResultEntry, buf: ByteBuffer) {
        when(value) {
            is AddressBulkTombstoneResultEntry.Success -> {
                buf.putInt(1)
                FfiConverterString.write(value.`guid`, buf)
                Unit
            }
            is AddressBulkTombstoneResultEntry.Error -> {
                buf.putInt(2)
                FfiConverterString.write(value.`message`, buf)
                Unit
            }
        }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
    }
}







sealed class AutofillApiException: kotlin.Exception() {
    
    class SqlException(
        
        val `reason`: kotlin.String
        ) : AutofillApiException() {
        override val message
            get() = "reason=${ `reason` }"
    }
    
    class InterruptedException(
        ) : AutofillApiException() {
        override val message
            get() = ""
    }
    
    class CryptoException(
        
        val `reason`: kotlin.String
        ) : AutofillApiException() {
        override val message
            get() = "reason=${ `reason` }"
    }
    
    class NoSuchRecord(
        
        val `guid`: kotlin.String
        ) : AutofillApiException() {
        override val message
            get() = "guid=${ `guid` }"
    }
    
    class UnexpectedAutofillApiException(
        
        val `reason`: kotlin.String
        ) : AutofillApiException() {
        override val message
            get() = "reason=${ `reason` }"
    }
    

    


    companion object ErrorHandler : UniffiRustCallStatusErrorHandler<AutofillApiException> {
        override fun lift(error_buf: RustBuffer.ByValue): AutofillApiException = FfiConverterTypeAutofillApiError.lift(error_buf)
    }

    
}

/**
 * @suppress
 */
public object FfiConverterTypeAutofillApiError : FfiConverterRustBuffer<AutofillApiException> {
    override fun read(buf: ByteBuffer): AutofillApiException {
        

        return when(buf.getInt()) {
            1 -> AutofillApiException.SqlException(
                FfiConverterString.read(buf),
                )
            2 -> AutofillApiException.InterruptedException()
            3 -> AutofillApiException.CryptoException(
                FfiConverterString.read(buf),
                )
            4 -> AutofillApiException.NoSuchRecord(
                FfiConverterString.read(buf),
                )
            5 -> AutofillApiException.UnexpectedAutofillApiException(
                FfiConverterString.read(buf),
                )
            else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
        }
    }

    override fun allocationSize(value: AutofillApiException): ULong {
        return when(value) {
            is AutofillApiException.SqlException -> (
                // Add the size for the Int that specifies the variant plus the size needed for all fields
                4UL
                + FfiConverterString.allocationSize(value.`reason`)
            )
            is AutofillApiException.InterruptedException -> (
                // Add the size for the Int that specifies the variant plus the size needed for all fields
                4UL
            )
            is AutofillApiException.CryptoException -> (
                // Add the size for the Int that specifies the variant plus the size needed for all fields
                4UL
                + FfiConverterString.allocationSize(value.`reason`)
            )
            is AutofillApiException.NoSuchRecord -> (
                // Add the size for the Int that specifies the variant plus the size needed for all fields
                4UL
                + FfiConverterString.allocationSize(value.`guid`)
            )
            is AutofillApiException.UnexpectedAutofillApiException -> (
                // Add the size for the Int that specifies the variant plus the size needed for all fields
                4UL
                + FfiConverterString.allocationSize(value.`reason`)
            )
        }
    }

    override fun write(value: AutofillApiException, buf: ByteBuffer) {
        when(value) {
            is AutofillApiException.SqlException -> {
                buf.putInt(1)
                FfiConverterString.write(value.`reason`, buf)
                Unit
            }
            is AutofillApiException.InterruptedException -> {
                buf.putInt(2)
                Unit
            }
            is AutofillApiException.CryptoException -> {
                buf.putInt(3)
                FfiConverterString.write(value.`reason`, buf)
                Unit
            }
            is AutofillApiException.NoSuchRecord -> {
                buf.putInt(4)
                FfiConverterString.write(value.`guid`, buf)
                Unit
            }
            is AutofillApiException.UnexpectedAutofillApiException -> {
                buf.putInt(5)
                FfiConverterString.write(value.`reason`, buf)
                Unit
            }
        }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
    }

}




/**
 * @suppress
 */
public object FfiConverterOptionalLong: FfiConverterRustBuffer<kotlin.Long?> {
    override fun read(buf: ByteBuffer): kotlin.Long? {
        if (buf.get().toInt() == 0) {
            return null
        }
        return FfiConverterLong.read(buf)
    }

    override fun allocationSize(value: kotlin.Long?): ULong {
        if (value == null) {
            return 1UL
        } else {
            return 1UL + FfiConverterLong.allocationSize(value)
        }
    }

    override fun write(value: kotlin.Long?, buf: ByteBuffer) {
        if (value == null) {
            buf.put(0)
        } else {
            buf.put(1)
            FfiConverterLong.write(value, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterOptionalString: FfiConverterRustBuffer<kotlin.String?> {
    override fun read(buf: ByteBuffer): kotlin.String? {
        if (buf.get().toInt() == 0) {
            return null
        }
        return FfiConverterString.read(buf)
    }

    override fun allocationSize(value: kotlin.String?): ULong {
        if (value == null) {
            return 1UL
        } else {
            return 1UL + FfiConverterString.allocationSize(value)
        }
    }

    override fun write(value: kotlin.String?, buf: ByteBuffer) {
        if (value == null) {
            buf.put(0)
        } else {
            buf.put(1)
            FfiConverterString.write(value, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterSequenceString: FfiConverterRustBuffer<List<kotlin.String>> {
    override fun read(buf: ByteBuffer): List<kotlin.String> {
        val len = buf.getInt()
        return List<kotlin.String>(len) {
            FfiConverterString.read(buf)
        }
    }

    override fun allocationSize(value: List<kotlin.String>): ULong {
        val sizeForLength = 4UL
        val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum()
        return sizeForLength + sizeForItems
    }

    override fun write(value: List<kotlin.String>, buf: ByteBuffer) {
        buf.putInt(value.size)
        value.iterator().forEach {
            FfiConverterString.write(it, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterSequenceTypeAddress: FfiConverterRustBuffer<List<Address>> {
    override fun read(buf: ByteBuffer): List<Address> {
        val len = buf.getInt()
        return List<Address>(len) {
            FfiConverterTypeAddress.read(buf)
        }
    }

    override fun allocationSize(value: List<Address>): ULong {
        val sizeForLength = 4UL
        val sizeForItems = value.map { FfiConverterTypeAddress.allocationSize(it) }.sum()
        return sizeForLength + sizeForItems
    }

    override fun write(value: List<Address>, buf: ByteBuffer) {
        buf.putInt(value.size)
        value.iterator().forEach {
            FfiConverterTypeAddress.write(it, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterSequenceTypeAddressTombstone: FfiConverterRustBuffer<List<AddressTombstone>> {
    override fun read(buf: ByteBuffer): List<AddressTombstone> {
        val len = buf.getInt()
        return List<AddressTombstone>(len) {
            FfiConverterTypeAddressTombstone.read(buf)
        }
    }

    override fun allocationSize(value: List<AddressTombstone>): ULong {
        val sizeForLength = 4UL
        val sizeForItems = value.map { FfiConverterTypeAddressTombstone.allocationSize(it) }.sum()
        return sizeForLength + sizeForItems
    }

    override fun write(value: List<AddressTombstone>, buf: ByteBuffer) {
        buf.putInt(value.size)
        value.iterator().forEach {
            FfiConverterTypeAddressTombstone.write(it, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterSequenceTypeCreditCard: FfiConverterRustBuffer<List<CreditCard>> {
    override fun read(buf: ByteBuffer): List<CreditCard> {
        val len = buf.getInt()
        return List<CreditCard>(len) {
            FfiConverterTypeCreditCard.read(buf)
        }
    }

    override fun allocationSize(value: List<CreditCard>): ULong {
        val sizeForLength = 4UL
        val sizeForItems = value.map { FfiConverterTypeCreditCard.allocationSize(it) }.sum()
        return sizeForLength + sizeForItems
    }

    override fun write(value: List<CreditCard>, buf: ByteBuffer) {
        buf.putInt(value.size)
        value.iterator().forEach {
            FfiConverterTypeCreditCard.write(it, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterSequenceTypePassport: FfiConverterRustBuffer<List<Passport>> {
    override fun read(buf: ByteBuffer): List<Passport> {
        val len = buf.getInt()
        return List<Passport>(len) {
            FfiConverterTypePassport.read(buf)
        }
    }

    override fun allocationSize(value: List<Passport>): ULong {
        val sizeForLength = 4UL
        val sizeForItems = value.map { FfiConverterTypePassport.allocationSize(it) }.sum()
        return sizeForLength + sizeForItems
    }

    override fun write(value: List<Passport>, buf: ByteBuffer) {
        buf.putInt(value.size)
        value.iterator().forEach {
            FfiConverterTypePassport.write(it, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterSequenceTypeUpdatableAddressFieldsWithMeta: FfiConverterRustBuffer<List<UpdatableAddressFieldsWithMeta>> {
    override fun read(buf: ByteBuffer): List<UpdatableAddressFieldsWithMeta> {
        val len = buf.getInt()
        return List<UpdatableAddressFieldsWithMeta>(len) {
            FfiConverterTypeUpdatableAddressFieldsWithMeta.read(buf)
        }
    }

    override fun allocationSize(value: List<UpdatableAddressFieldsWithMeta>): ULong {
        val sizeForLength = 4UL
        val sizeForItems = value.map { FfiConverterTypeUpdatableAddressFieldsWithMeta.allocationSize(it) }.sum()
        return sizeForLength + sizeForItems
    }

    override fun write(value: List<UpdatableAddressFieldsWithMeta>, buf: ByteBuffer) {
        buf.putInt(value.size)
        value.iterator().forEach {
            FfiConverterTypeUpdatableAddressFieldsWithMeta.write(it, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterSequenceTypeAddressBulkResultEntry: FfiConverterRustBuffer<List<AddressBulkResultEntry>> {
    override fun read(buf: ByteBuffer): List<AddressBulkResultEntry> {
        val len = buf.getInt()
        return List<AddressBulkResultEntry>(len) {
            FfiConverterTypeAddressBulkResultEntry.read(buf)
        }
    }

    override fun allocationSize(value: List<AddressBulkResultEntry>): ULong {
        val sizeForLength = 4UL
        val sizeForItems = value.map { FfiConverterTypeAddressBulkResultEntry.allocationSize(it) }.sum()
        return sizeForLength + sizeForItems
    }

    override fun write(value: List<AddressBulkResultEntry>, buf: ByteBuffer) {
        buf.putInt(value.size)
        value.iterator().forEach {
            FfiConverterTypeAddressBulkResultEntry.write(it, buf)
        }
    }
}




/**
 * @suppress
 */
public object FfiConverterSequenceTypeAddressBulkTombstoneResultEntry: FfiConverterRustBuffer<List<AddressBulkTombstoneResultEntry>> {
    override fun read(buf: ByteBuffer): List<AddressBulkTombstoneResultEntry> {
        val len = buf.getInt()
        return List<AddressBulkTombstoneResultEntry>(len) {
            FfiConverterTypeAddressBulkTombstoneResultEntry.read(buf)
        }
    }

    override fun allocationSize(value: List<AddressBulkTombstoneResultEntry>): ULong {
        val sizeForLength = 4UL
        val sizeForItems = value.map { FfiConverterTypeAddressBulkTombstoneResultEntry.allocationSize(it) }.sum()
        return sizeForLength + sizeForItems
    }

    override fun write(value: List<AddressBulkTombstoneResultEntry>, buf: ByteBuffer) {
        buf.putInt(value.size)
        value.iterator().forEach {
            FfiConverterTypeAddressBulkTombstoneResultEntry.write(it, buf)
        }
    }
}
        /**
         * Create a new, random, encryption key.
         */
    @Throws(AutofillApiException::class) fun `createAutofillKey`(): kotlin.String {
            return FfiConverterString.lift(
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_func_create_autofill_key(
    
        _status)
}
    )
    }
    

        /**
         * Decrypt an arbitrary string - `key` must have come from `create_key()`
         * and `ciphertext` must have come from `encrypt_string()`
         */
    @Throws(AutofillApiException::class) fun `decryptString`(`key`: kotlin.String, `ciphertext`: kotlin.String): kotlin.String {
            return FfiConverterString.lift(
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_func_decrypt_string(
    
        FfiConverterString.lower(`key`),FfiConverterString.lower(`ciphertext`),_status)
}
    )
    }
    

        /**
         * Encrypt an arbitrary string - `key` must have come from `create_key()`
         */
    @Throws(AutofillApiException::class) fun `encryptString`(`key`: kotlin.String, `cleartext`: kotlin.String): kotlin.String {
            return FfiConverterString.lift(
    uniffiRustCallWithError(AutofillApiException) { _status ->
    UniffiLib.uniffi_autofill_fn_func_encrypt_string(
    
        FfiConverterString.lower(`key`),FfiConverterString.lower(`cleartext`),_status)
}
    )
    }
    


