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

// swiftlint:disable all
import Foundation

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        default:
            throw UniffiInternalError.unexpectedRustCallStatusCode
    }
}

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

private func uniffiTraitInterfaceCallWithError<T, E>(
    callStatus: UnsafeMutablePointer<RustCallStatus>,
    makeCall: () throws -> T,
    writeReturn: (T) -> (),
    lowerError: (E) -> RustBuffer
) {
    do {
        try writeReturn(makeCall())
    } catch let error as E {
        callStatus.pointee.code = CALL_ERROR
        callStatus.pointee.errorBuf = lowerError(error)
    } catch {
        callStatus.pointee.code = CALL_UNEXPECTED_ERROR
        callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
    }
}
fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
    // All mutation happens with this lock held, which is why we implement @unchecked Sendable.
    private let lock = NSLock()
    private var map: [UInt64: T] = [:]
    private var currentHandle: UInt64 = 1

    func insert(obj: T) -> UInt64 {
        lock.withLock {
            let handle = currentHandle
            currentHandle += 1
            map[handle] = obj
            return handle
        }
    }

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

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

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


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

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
    typealias FfiType = UInt32
    typealias SwiftType = UInt32

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

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

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterUInt64: FfiConverterPrimitive {
    typealias FfiType = UInt64
    typealias SwiftType = UInt64

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

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

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDouble: FfiConverterPrimitive {
    typealias FfiType = Double
    typealias SwiftType = Double

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

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

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

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

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

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

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




public protocol MozAdsClientProtocol: AnyObject, Sendable {
    
    func clearCache() throws 
    
    func cycleContextId() throws  -> String
    
    func recordClick(clickUrl: String) throws 
    
    func recordImpression(impressionUrl: String) throws 
    
    func reportAd(reportUrl: String) throws 
    
    func requestImageAds(mozAdRequests: [MozAdsPlacementRequest], options: MozAdsRequestOptions?) throws  -> [String: MozAdsImage]
    
    func requestSpocAds(mozAdRequests: [MozAdsPlacementRequestWithCount], options: MozAdsRequestOptions?) throws  -> [String: [MozAdsSpoc]]
    
    func requestTileAds(mozAdRequests: [MozAdsPlacementRequest], options: MozAdsRequestOptions?) throws  -> [String: MozAdsTile]
    
}
open class MozAdsClient: MozAdsClientProtocol, @unchecked Sendable {
    fileprivate let pointer: UnsafeMutableRawPointer!

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

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

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

#if swift(>=5.8)
    @_documentation(visibility: private)
#endif
    public func uniffiClonePointer() -> UnsafeMutableRawPointer {
        return try! rustCall { uniffi_ads_client_fn_clone_mozadsclient(self.pointer, $0) }
    }
public convenience init(clientConfig: MozAdsClientConfig?) {
    let pointer =
        try! rustCall() {
    uniffi_ads_client_fn_constructor_mozadsclient_new(
        FfiConverterOptionTypeMozAdsClientConfig.lower(clientConfig),$0
    )
}
    self.init(unsafeFromRawPointer: pointer)
}

    deinit {
        guard let pointer = pointer else {
            return
        }

        try! rustCall { uniffi_ads_client_fn_free_mozadsclient(pointer, $0) }
    }

    

    
open func clearCache()throws   {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
    uniffi_ads_client_fn_method_mozadsclient_clear_cache(self.uniffiClonePointer(),$0
    )
}
}
    
open func cycleContextId()throws  -> String  {
    return try  FfiConverterString.lift(try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
    uniffi_ads_client_fn_method_mozadsclient_cycle_context_id(self.uniffiClonePointer(),$0
    )
})
}
    
open func recordClick(clickUrl: String)throws   {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
    uniffi_ads_client_fn_method_mozadsclient_record_click(self.uniffiClonePointer(),
        FfiConverterString.lower(clickUrl),$0
    )
}
}
    
open func recordImpression(impressionUrl: String)throws   {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
    uniffi_ads_client_fn_method_mozadsclient_record_impression(self.uniffiClonePointer(),
        FfiConverterString.lower(impressionUrl),$0
    )
}
}
    
open func reportAd(reportUrl: String)throws   {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
    uniffi_ads_client_fn_method_mozadsclient_report_ad(self.uniffiClonePointer(),
        FfiConverterString.lower(reportUrl),$0
    )
}
}
    
open func requestImageAds(mozAdRequests: [MozAdsPlacementRequest], options: MozAdsRequestOptions?)throws  -> [String: MozAdsImage]  {
    return try  FfiConverterDictionaryStringTypeMozAdsImage.lift(try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
    uniffi_ads_client_fn_method_mozadsclient_request_image_ads(self.uniffiClonePointer(),
        FfiConverterSequenceTypeMozAdsPlacementRequest.lower(mozAdRequests),
        FfiConverterOptionTypeMozAdsRequestOptions.lower(options),$0
    )
})
}
    
open func requestSpocAds(mozAdRequests: [MozAdsPlacementRequestWithCount], options: MozAdsRequestOptions?)throws  -> [String: [MozAdsSpoc]]  {
    return try  FfiConverterDictionaryStringSequenceTypeMozAdsSpoc.lift(try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
    uniffi_ads_client_fn_method_mozadsclient_request_spoc_ads(self.uniffiClonePointer(),
        FfiConverterSequenceTypeMozAdsPlacementRequestWithCount.lower(mozAdRequests),
        FfiConverterOptionTypeMozAdsRequestOptions.lower(options),$0
    )
})
}
    
open func requestTileAds(mozAdRequests: [MozAdsPlacementRequest], options: MozAdsRequestOptions?)throws  -> [String: MozAdsTile]  {
    return try  FfiConverterDictionaryStringTypeMozAdsTile.lift(try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
    uniffi_ads_client_fn_method_mozadsclient_request_tile_ads(self.uniffiClonePointer(),
        FfiConverterSequenceTypeMozAdsPlacementRequest.lower(mozAdRequests),
        FfiConverterOptionTypeMozAdsRequestOptions.lower(options),$0
    )
})
}
    

}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsClient: FfiConverter {

    typealias FfiType = UnsafeMutableRawPointer
    typealias SwiftType = MozAdsClient

    public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MozAdsClient {
        return MozAdsClient(unsafeFromRawPointer: pointer)
    }

    public static func lower(_ value: MozAdsClient) -> UnsafeMutableRawPointer {
        return value.uniffiClonePointer()
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsClient {
        let v: UInt64 = try readInt(&buf)
        // The Rust code won't compile if a pointer won't fit in a UInt64.
        // We have to go via `UInt` because that's the thing that's the size of a pointer.
        let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
        if (ptr == nil) {
            throw UniffiInternalError.unexpectedNullPointer
        }
        return try lift(ptr!)
    }

    public static func write(_ value: MozAdsClient, into buf: inout [UInt8]) {
        // This fiddling is because `Int` is the thing that's the same size as a pointer.
        // The Rust code won't compile if a pointer won't fit in a `UInt64`.
        writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> MozAdsClient {
    return try FfiConverterTypeMozAdsClient.lift(pointer)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsClient_lower(_ value: MozAdsClient) -> UnsafeMutableRawPointer {
    return FfiConverterTypeMozAdsClient.lower(value)
}






public protocol MozAdsTelemetry: AnyObject, Sendable {
    
    func recordBuildCacheError(label: String, value: String) 
    
    func recordClientError(label: String, value: String) 
    
    func recordClientOperationTotal(label: String) 
    
    func recordDeserializationError(label: String, value: String) 
    
    func recordHttpCacheOutcome(label: String, value: String) 
    
}
open class MozAdsTelemetryImpl: MozAdsTelemetry, @unchecked Sendable {
    fileprivate let pointer: UnsafeMutableRawPointer!

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

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

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

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

    deinit {
        guard let pointer = pointer else {
            return
        }

        try! rustCall { uniffi_ads_client_fn_free_mozadstelemetry(pointer, $0) }
    }

    

    
open func recordBuildCacheError(label: String, value: String)  {try! rustCall() {
    uniffi_ads_client_fn_method_mozadstelemetry_record_build_cache_error(self.uniffiClonePointer(),
        FfiConverterString.lower(label),
        FfiConverterString.lower(value),$0
    )
}
}
    
open func recordClientError(label: String, value: String)  {try! rustCall() {
    uniffi_ads_client_fn_method_mozadstelemetry_record_client_error(self.uniffiClonePointer(),
        FfiConverterString.lower(label),
        FfiConverterString.lower(value),$0
    )
}
}
    
open func recordClientOperationTotal(label: String)  {try! rustCall() {
    uniffi_ads_client_fn_method_mozadstelemetry_record_client_operation_total(self.uniffiClonePointer(),
        FfiConverterString.lower(label),$0
    )
}
}
    
open func recordDeserializationError(label: String, value: String)  {try! rustCall() {
    uniffi_ads_client_fn_method_mozadstelemetry_record_deserialization_error(self.uniffiClonePointer(),
        FfiConverterString.lower(label),
        FfiConverterString.lower(value),$0
    )
}
}
    
open func recordHttpCacheOutcome(label: String, value: String)  {try! rustCall() {
    uniffi_ads_client_fn_method_mozadstelemetry_record_http_cache_outcome(self.uniffiClonePointer(),
        FfiConverterString.lower(label),
        FfiConverterString.lower(value),$0
    )
}
}
    

}


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

    // Create the VTable using a series of closures.
    // Swift automatically converts these into C callback functions.
    //
    // This creates 1-element array, since this seems to be the only way to construct a const
    // pointer that we can pass to the Rust code.
    static let vtable: [UniffiVTableCallbackInterfaceMozAdsTelemetry] = [UniffiVTableCallbackInterfaceMozAdsTelemetry(
        recordBuildCacheError: { (
            uniffiHandle: UInt64,
            label: RustBuffer,
            value: RustBuffer,
            uniffiOutReturn: UnsafeMutableRawPointer,
            uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
        ) in
            let makeCall = {
                () throws -> () in
                guard let uniffiObj = try? FfiConverterTypeMozAdsTelemetry.handleMap.get(handle: uniffiHandle) else {
                    throw UniffiInternalError.unexpectedStaleHandle
                }
                return uniffiObj.recordBuildCacheError(
                     label: try FfiConverterString.lift(label),
                     value: try FfiConverterString.lift(value)
                )
            }

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

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

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

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

            
            let writeReturn = { () }
            uniffiTraitInterfaceCall(
                callStatus: uniffiCallStatus,
                makeCall: makeCall,
                writeReturn: writeReturn
            )
        },
        uniffiFree: { (uniffiHandle: UInt64) -> () in
            let result = try? FfiConverterTypeMozAdsTelemetry.handleMap.remove(handle: uniffiHandle)
            if result == nil {
                print("Uniffi callback interface MozAdsTelemetry: handle missing in uniffiFree")
            }
        }
    )]
}

private func uniffiCallbackInitMozAdsTelemetry() {
    uniffi_ads_client_fn_init_callback_vtable_mozadstelemetry(UniffiCallbackInterfaceMozAdsTelemetry.vtable)
}


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

    typealias FfiType = UnsafeMutableRawPointer
    typealias SwiftType = MozAdsTelemetry

    public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MozAdsTelemetry {
        return MozAdsTelemetryImpl(unsafeFromRawPointer: pointer)
    }

    public static func lower(_ value: MozAdsTelemetry) -> UnsafeMutableRawPointer {
        guard let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: handleMap.insert(obj: value))) else {
            fatalError("Cast to UnsafeMutableRawPointer failed")
        }
        return ptr
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsTelemetry {
        let v: UInt64 = try readInt(&buf)
        // The Rust code won't compile if a pointer won't fit in a UInt64.
        // We have to go via `UInt` because that's the thing that's the size of a pointer.
        let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
        if (ptr == nil) {
            throw UniffiInternalError.unexpectedNullPointer
        }
        return try lift(ptr!)
    }

    public static func write(_ value: MozAdsTelemetry, into buf: inout [UInt8]) {
        // This fiddling is because `Int` is the thing that's the same size as a pointer.
        // The Rust code won't compile if a pointer won't fit in a `UInt64`.
        writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsTelemetry_lift(_ pointer: UnsafeMutableRawPointer) throws -> MozAdsTelemetry {
    return try FfiConverterTypeMozAdsTelemetry.lift(pointer)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsTelemetry_lower(_ value: MozAdsTelemetry) -> UnsafeMutableRawPointer {
    return FfiConverterTypeMozAdsTelemetry.lower(value)
}




public struct MozAdsCacheConfig {
    public var dbPath: String
    public var defaultCacheTtlSeconds: UInt64?
    public var maxSizeMib: UInt64?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(dbPath: String, defaultCacheTtlSeconds: UInt64?, maxSizeMib: UInt64?) {
        self.dbPath = dbPath
        self.defaultCacheTtlSeconds = defaultCacheTtlSeconds
        self.maxSizeMib = maxSizeMib
    }
}

#if compiler(>=6)
extension MozAdsCacheConfig: Sendable {}
#endif


extension MozAdsCacheConfig: Equatable, Hashable {
    public static func ==(lhs: MozAdsCacheConfig, rhs: MozAdsCacheConfig) -> Bool {
        if lhs.dbPath != rhs.dbPath {
            return false
        }
        if lhs.defaultCacheTtlSeconds != rhs.defaultCacheTtlSeconds {
            return false
        }
        if lhs.maxSizeMib != rhs.maxSizeMib {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(dbPath)
        hasher.combine(defaultCacheTtlSeconds)
        hasher.combine(maxSizeMib)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsCacheConfig: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsCacheConfig {
        return
            try MozAdsCacheConfig(
                dbPath: FfiConverterString.read(from: &buf), 
                defaultCacheTtlSeconds: FfiConverterOptionUInt64.read(from: &buf), 
                maxSizeMib: FfiConverterOptionUInt64.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsCacheConfig, into buf: inout [UInt8]) {
        FfiConverterString.write(value.dbPath, into: &buf)
        FfiConverterOptionUInt64.write(value.defaultCacheTtlSeconds, into: &buf)
        FfiConverterOptionUInt64.write(value.maxSizeMib, into: &buf)
    }
}


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

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


public struct MozAdsCallbacks {
    public var click: AdsClientUrl
    public var impression: AdsClientUrl
    public var report: AdsClientUrl?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(click: AdsClientUrl, impression: AdsClientUrl, report: AdsClientUrl?) {
        self.click = click
        self.impression = impression
        self.report = report
    }
}

#if compiler(>=6)
extension MozAdsCallbacks: Sendable {}
#endif


extension MozAdsCallbacks: Equatable, Hashable {
    public static func ==(lhs: MozAdsCallbacks, rhs: MozAdsCallbacks) -> Bool {
        if lhs.click != rhs.click {
            return false
        }
        if lhs.impression != rhs.impression {
            return false
        }
        if lhs.report != rhs.report {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(click)
        hasher.combine(impression)
        hasher.combine(report)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsCallbacks: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsCallbacks {
        return
            try MozAdsCallbacks(
                click: FfiConverterTypeAdsClientUrl.read(from: &buf), 
                impression: FfiConverterTypeAdsClientUrl.read(from: &buf), 
                report: FfiConverterOptionTypeAdsClientUrl.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsCallbacks, into buf: inout [UInt8]) {
        FfiConverterTypeAdsClientUrl.write(value.click, into: &buf)
        FfiConverterTypeAdsClientUrl.write(value.impression, into: &buf)
        FfiConverterOptionTypeAdsClientUrl.write(value.report, into: &buf)
    }
}


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

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


public struct MozAdsClientConfig {
    public var environment: MozAdsEnvironment
    public var cacheConfig: MozAdsCacheConfig?
    public var telemetry: MozAdsTelemetry?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(environment: MozAdsEnvironment, cacheConfig: MozAdsCacheConfig?, telemetry: MozAdsTelemetry?) {
        self.environment = environment
        self.cacheConfig = cacheConfig
        self.telemetry = telemetry
    }
}

#if compiler(>=6)
extension MozAdsClientConfig: Sendable {}
#endif



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsClientConfig: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsClientConfig {
        return
            try MozAdsClientConfig(
                environment: FfiConverterTypeMozAdsEnvironment.read(from: &buf), 
                cacheConfig: FfiConverterOptionTypeMozAdsCacheConfig.read(from: &buf), 
                telemetry: FfiConverterOptionTypeMozAdsTelemetry.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsClientConfig, into buf: inout [UInt8]) {
        FfiConverterTypeMozAdsEnvironment.write(value.environment, into: &buf)
        FfiConverterOptionTypeMozAdsCacheConfig.write(value.cacheConfig, into: &buf)
        FfiConverterOptionTypeMozAdsTelemetry.write(value.telemetry, into: &buf)
    }
}


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

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


public struct MozAdsContentCategory {
    public var taxonomy: MozAdsIabContentTaxonomy
    public var categories: [String]

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(taxonomy: MozAdsIabContentTaxonomy, categories: [String]) {
        self.taxonomy = taxonomy
        self.categories = categories
    }
}

#if compiler(>=6)
extension MozAdsContentCategory: Sendable {}
#endif


extension MozAdsContentCategory: Equatable, Hashable {
    public static func ==(lhs: MozAdsContentCategory, rhs: MozAdsContentCategory) -> Bool {
        if lhs.taxonomy != rhs.taxonomy {
            return false
        }
        if lhs.categories != rhs.categories {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(taxonomy)
        hasher.combine(categories)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsContentCategory: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsContentCategory {
        return
            try MozAdsContentCategory(
                taxonomy: FfiConverterTypeMozAdsIABContentTaxonomy.read(from: &buf), 
                categories: FfiConverterSequenceString.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsContentCategory, into buf: inout [UInt8]) {
        FfiConverterTypeMozAdsIABContentTaxonomy.write(value.taxonomy, into: &buf)
        FfiConverterSequenceString.write(value.categories, into: &buf)
    }
}


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

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


public struct MozAdsIabContent {
    public var taxonomy: MozAdsIabContentTaxonomy
    public var categoryIds: [String]

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(taxonomy: MozAdsIabContentTaxonomy, categoryIds: [String]) {
        self.taxonomy = taxonomy
        self.categoryIds = categoryIds
    }
}

#if compiler(>=6)
extension MozAdsIabContent: Sendable {}
#endif


extension MozAdsIabContent: Equatable, Hashable {
    public static func ==(lhs: MozAdsIabContent, rhs: MozAdsIabContent) -> Bool {
        if lhs.taxonomy != rhs.taxonomy {
            return false
        }
        if lhs.categoryIds != rhs.categoryIds {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(taxonomy)
        hasher.combine(categoryIds)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsIABContent: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsIabContent {
        return
            try MozAdsIabContent(
                taxonomy: FfiConverterTypeMozAdsIABContentTaxonomy.read(from: &buf), 
                categoryIds: FfiConverterSequenceString.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsIabContent, into buf: inout [UInt8]) {
        FfiConverterTypeMozAdsIABContentTaxonomy.write(value.taxonomy, into: &buf)
        FfiConverterSequenceString.write(value.categoryIds, into: &buf)
    }
}


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

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


public struct MozAdsImage {
    public var altText: String?
    public var blockKey: String
    public var callbacks: MozAdsCallbacks
    public var format: String
    public var imageUrl: String
    public var url: String

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(altText: String?, blockKey: String, callbacks: MozAdsCallbacks, format: String, imageUrl: String, url: String) {
        self.altText = altText
        self.blockKey = blockKey
        self.callbacks = callbacks
        self.format = format
        self.imageUrl = imageUrl
        self.url = url
    }
}

#if compiler(>=6)
extension MozAdsImage: Sendable {}
#endif


extension MozAdsImage: Equatable, Hashable {
    public static func ==(lhs: MozAdsImage, rhs: MozAdsImage) -> Bool {
        if lhs.altText != rhs.altText {
            return false
        }
        if lhs.blockKey != rhs.blockKey {
            return false
        }
        if lhs.callbacks != rhs.callbacks {
            return false
        }
        if lhs.format != rhs.format {
            return false
        }
        if lhs.imageUrl != rhs.imageUrl {
            return false
        }
        if lhs.url != rhs.url {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(altText)
        hasher.combine(blockKey)
        hasher.combine(callbacks)
        hasher.combine(format)
        hasher.combine(imageUrl)
        hasher.combine(url)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsImage: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsImage {
        return
            try MozAdsImage(
                altText: FfiConverterOptionString.read(from: &buf), 
                blockKey: FfiConverterString.read(from: &buf), 
                callbacks: FfiConverterTypeMozAdsCallbacks.read(from: &buf), 
                format: FfiConverterString.read(from: &buf), 
                imageUrl: FfiConverterString.read(from: &buf), 
                url: FfiConverterString.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsImage, into buf: inout [UInt8]) {
        FfiConverterOptionString.write(value.altText, into: &buf)
        FfiConverterString.write(value.blockKey, into: &buf)
        FfiConverterTypeMozAdsCallbacks.write(value.callbacks, into: &buf)
        FfiConverterString.write(value.format, into: &buf)
        FfiConverterString.write(value.imageUrl, into: &buf)
        FfiConverterString.write(value.url, into: &buf)
    }
}


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

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


public struct MozAdsPlacementRequest {
    public var placementId: String
    public var iabContent: MozAdsIabContent?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(placementId: String, iabContent: MozAdsIabContent?) {
        self.placementId = placementId
        self.iabContent = iabContent
    }
}

#if compiler(>=6)
extension MozAdsPlacementRequest: Sendable {}
#endif


extension MozAdsPlacementRequest: Equatable, Hashable {
    public static func ==(lhs: MozAdsPlacementRequest, rhs: MozAdsPlacementRequest) -> Bool {
        if lhs.placementId != rhs.placementId {
            return false
        }
        if lhs.iabContent != rhs.iabContent {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(placementId)
        hasher.combine(iabContent)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsPlacementRequest: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsPlacementRequest {
        return
            try MozAdsPlacementRequest(
                placementId: FfiConverterString.read(from: &buf), 
                iabContent: FfiConverterOptionTypeMozAdsIABContent.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsPlacementRequest, into buf: inout [UInt8]) {
        FfiConverterString.write(value.placementId, into: &buf)
        FfiConverterOptionTypeMozAdsIABContent.write(value.iabContent, into: &buf)
    }
}


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

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


public struct MozAdsPlacementRequestWithCount {
    public var count: UInt32
    public var placementId: String
    public var iabContent: MozAdsIabContent?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(count: UInt32, placementId: String, iabContent: MozAdsIabContent?) {
        self.count = count
        self.placementId = placementId
        self.iabContent = iabContent
    }
}

#if compiler(>=6)
extension MozAdsPlacementRequestWithCount: Sendable {}
#endif


extension MozAdsPlacementRequestWithCount: Equatable, Hashable {
    public static func ==(lhs: MozAdsPlacementRequestWithCount, rhs: MozAdsPlacementRequestWithCount) -> Bool {
        if lhs.count != rhs.count {
            return false
        }
        if lhs.placementId != rhs.placementId {
            return false
        }
        if lhs.iabContent != rhs.iabContent {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(count)
        hasher.combine(placementId)
        hasher.combine(iabContent)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsPlacementRequestWithCount: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsPlacementRequestWithCount {
        return
            try MozAdsPlacementRequestWithCount(
                count: FfiConverterUInt32.read(from: &buf), 
                placementId: FfiConverterString.read(from: &buf), 
                iabContent: FfiConverterOptionTypeMozAdsIABContent.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsPlacementRequestWithCount, into buf: inout [UInt8]) {
        FfiConverterUInt32.write(value.count, into: &buf)
        FfiConverterString.write(value.placementId, into: &buf)
        FfiConverterOptionTypeMozAdsIABContent.write(value.iabContent, into: &buf)
    }
}


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

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


public struct MozAdsRequestCachePolicy {
    public var mode: MozAdsCacheMode
    public var ttlSeconds: UInt64?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(mode: MozAdsCacheMode, ttlSeconds: UInt64?) {
        self.mode = mode
        self.ttlSeconds = ttlSeconds
    }
}

#if compiler(>=6)
extension MozAdsRequestCachePolicy: Sendable {}
#endif


extension MozAdsRequestCachePolicy: Equatable, Hashable {
    public static func ==(lhs: MozAdsRequestCachePolicy, rhs: MozAdsRequestCachePolicy) -> Bool {
        if lhs.mode != rhs.mode {
            return false
        }
        if lhs.ttlSeconds != rhs.ttlSeconds {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(mode)
        hasher.combine(ttlSeconds)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsRequestCachePolicy: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsRequestCachePolicy {
        return
            try MozAdsRequestCachePolicy(
                mode: FfiConverterTypeMozAdsCacheMode.read(from: &buf), 
                ttlSeconds: FfiConverterOptionUInt64.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsRequestCachePolicy, into buf: inout [UInt8]) {
        FfiConverterTypeMozAdsCacheMode.write(value.mode, into: &buf)
        FfiConverterOptionUInt64.write(value.ttlSeconds, into: &buf)
    }
}


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

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


public struct MozAdsRequestOptions {
    public var cachePolicy: MozAdsRequestCachePolicy?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(cachePolicy: MozAdsRequestCachePolicy?) {
        self.cachePolicy = cachePolicy
    }
}

#if compiler(>=6)
extension MozAdsRequestOptions: Sendable {}
#endif


extension MozAdsRequestOptions: Equatable, Hashable {
    public static func ==(lhs: MozAdsRequestOptions, rhs: MozAdsRequestOptions) -> Bool {
        if lhs.cachePolicy != rhs.cachePolicy {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(cachePolicy)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsRequestOptions: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsRequestOptions {
        return
            try MozAdsRequestOptions(
                cachePolicy: FfiConverterOptionTypeMozAdsRequestCachePolicy.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsRequestOptions, into buf: inout [UInt8]) {
        FfiConverterOptionTypeMozAdsRequestCachePolicy.write(value.cachePolicy, into: &buf)
    }
}


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

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


public struct MozAdsSpoc {
    public var blockKey: String
    public var callbacks: MozAdsCallbacks
    public var caps: MozAdsSpocFrequencyCaps
    public var domain: String
    public var excerpt: String
    public var format: String
    public var imageUrl: String
    public var ranking: MozAdsSpocRanking
    public var sponsor: String
    public var sponsoredByOverride: String?
    public var title: String
    public var url: String

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(blockKey: String, callbacks: MozAdsCallbacks, caps: MozAdsSpocFrequencyCaps, domain: String, excerpt: String, format: String, imageUrl: String, ranking: MozAdsSpocRanking, sponsor: String, sponsoredByOverride: String?, title: String, url: String) {
        self.blockKey = blockKey
        self.callbacks = callbacks
        self.caps = caps
        self.domain = domain
        self.excerpt = excerpt
        self.format = format
        self.imageUrl = imageUrl
        self.ranking = ranking
        self.sponsor = sponsor
        self.sponsoredByOverride = sponsoredByOverride
        self.title = title
        self.url = url
    }
}

#if compiler(>=6)
extension MozAdsSpoc: Sendable {}
#endif


extension MozAdsSpoc: Equatable, Hashable {
    public static func ==(lhs: MozAdsSpoc, rhs: MozAdsSpoc) -> Bool {
        if lhs.blockKey != rhs.blockKey {
            return false
        }
        if lhs.callbacks != rhs.callbacks {
            return false
        }
        if lhs.caps != rhs.caps {
            return false
        }
        if lhs.domain != rhs.domain {
            return false
        }
        if lhs.excerpt != rhs.excerpt {
            return false
        }
        if lhs.format != rhs.format {
            return false
        }
        if lhs.imageUrl != rhs.imageUrl {
            return false
        }
        if lhs.ranking != rhs.ranking {
            return false
        }
        if lhs.sponsor != rhs.sponsor {
            return false
        }
        if lhs.sponsoredByOverride != rhs.sponsoredByOverride {
            return false
        }
        if lhs.title != rhs.title {
            return false
        }
        if lhs.url != rhs.url {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(blockKey)
        hasher.combine(callbacks)
        hasher.combine(caps)
        hasher.combine(domain)
        hasher.combine(excerpt)
        hasher.combine(format)
        hasher.combine(imageUrl)
        hasher.combine(ranking)
        hasher.combine(sponsor)
        hasher.combine(sponsoredByOverride)
        hasher.combine(title)
        hasher.combine(url)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsSpoc: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsSpoc {
        return
            try MozAdsSpoc(
                blockKey: FfiConverterString.read(from: &buf), 
                callbacks: FfiConverterTypeMozAdsCallbacks.read(from: &buf), 
                caps: FfiConverterTypeMozAdsSpocFrequencyCaps.read(from: &buf), 
                domain: FfiConverterString.read(from: &buf), 
                excerpt: FfiConverterString.read(from: &buf), 
                format: FfiConverterString.read(from: &buf), 
                imageUrl: FfiConverterString.read(from: &buf), 
                ranking: FfiConverterTypeMozAdsSpocRanking.read(from: &buf), 
                sponsor: FfiConverterString.read(from: &buf), 
                sponsoredByOverride: FfiConverterOptionString.read(from: &buf), 
                title: FfiConverterString.read(from: &buf), 
                url: FfiConverterString.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsSpoc, into buf: inout [UInt8]) {
        FfiConverterString.write(value.blockKey, into: &buf)
        FfiConverterTypeMozAdsCallbacks.write(value.callbacks, into: &buf)
        FfiConverterTypeMozAdsSpocFrequencyCaps.write(value.caps, into: &buf)
        FfiConverterString.write(value.domain, into: &buf)
        FfiConverterString.write(value.excerpt, into: &buf)
        FfiConverterString.write(value.format, into: &buf)
        FfiConverterString.write(value.imageUrl, into: &buf)
        FfiConverterTypeMozAdsSpocRanking.write(value.ranking, into: &buf)
        FfiConverterString.write(value.sponsor, into: &buf)
        FfiConverterOptionString.write(value.sponsoredByOverride, into: &buf)
        FfiConverterString.write(value.title, into: &buf)
        FfiConverterString.write(value.url, into: &buf)
    }
}


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

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


public struct MozAdsSpocFrequencyCaps {
    public var capKey: String
    public var day: UInt32

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(capKey: String, day: UInt32) {
        self.capKey = capKey
        self.day = day
    }
}

#if compiler(>=6)
extension MozAdsSpocFrequencyCaps: Sendable {}
#endif


extension MozAdsSpocFrequencyCaps: Equatable, Hashable {
    public static func ==(lhs: MozAdsSpocFrequencyCaps, rhs: MozAdsSpocFrequencyCaps) -> Bool {
        if lhs.capKey != rhs.capKey {
            return false
        }
        if lhs.day != rhs.day {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(capKey)
        hasher.combine(day)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsSpocFrequencyCaps: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsSpocFrequencyCaps {
        return
            try MozAdsSpocFrequencyCaps(
                capKey: FfiConverterString.read(from: &buf), 
                day: FfiConverterUInt32.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsSpocFrequencyCaps, into buf: inout [UInt8]) {
        FfiConverterString.write(value.capKey, into: &buf)
        FfiConverterUInt32.write(value.day, into: &buf)
    }
}


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

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


public struct MozAdsSpocRanking {
    public var priority: UInt32
    public var personalizationModels: [String: UInt32]
    public var itemScore: Double

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(priority: UInt32, personalizationModels: [String: UInt32], itemScore: Double) {
        self.priority = priority
        self.personalizationModels = personalizationModels
        self.itemScore = itemScore
    }
}

#if compiler(>=6)
extension MozAdsSpocRanking: Sendable {}
#endif


extension MozAdsSpocRanking: Equatable, Hashable {
    public static func ==(lhs: MozAdsSpocRanking, rhs: MozAdsSpocRanking) -> Bool {
        if lhs.priority != rhs.priority {
            return false
        }
        if lhs.personalizationModels != rhs.personalizationModels {
            return false
        }
        if lhs.itemScore != rhs.itemScore {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(priority)
        hasher.combine(personalizationModels)
        hasher.combine(itemScore)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsSpocRanking: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsSpocRanking {
        return
            try MozAdsSpocRanking(
                priority: FfiConverterUInt32.read(from: &buf), 
                personalizationModels: FfiConverterDictionaryStringUInt32.read(from: &buf), 
                itemScore: FfiConverterDouble.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsSpocRanking, into buf: inout [UInt8]) {
        FfiConverterUInt32.write(value.priority, into: &buf)
        FfiConverterDictionaryStringUInt32.write(value.personalizationModels, into: &buf)
        FfiConverterDouble.write(value.itemScore, into: &buf)
    }
}


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

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


public struct MozAdsTile {
    public var blockKey: String
    public var callbacks: MozAdsCallbacks
    public var format: String
    public var imageUrl: String
    public var name: String
    public var url: String

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(blockKey: String, callbacks: MozAdsCallbacks, format: String, imageUrl: String, name: String, url: String) {
        self.blockKey = blockKey
        self.callbacks = callbacks
        self.format = format
        self.imageUrl = imageUrl
        self.name = name
        self.url = url
    }
}

#if compiler(>=6)
extension MozAdsTile: Sendable {}
#endif


extension MozAdsTile: Equatable, Hashable {
    public static func ==(lhs: MozAdsTile, rhs: MozAdsTile) -> Bool {
        if lhs.blockKey != rhs.blockKey {
            return false
        }
        if lhs.callbacks != rhs.callbacks {
            return false
        }
        if lhs.format != rhs.format {
            return false
        }
        if lhs.imageUrl != rhs.imageUrl {
            return false
        }
        if lhs.name != rhs.name {
            return false
        }
        if lhs.url != rhs.url {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(blockKey)
        hasher.combine(callbacks)
        hasher.combine(format)
        hasher.combine(imageUrl)
        hasher.combine(name)
        hasher.combine(url)
    }
}



#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsTile: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsTile {
        return
            try MozAdsTile(
                blockKey: FfiConverterString.read(from: &buf), 
                callbacks: FfiConverterTypeMozAdsCallbacks.read(from: &buf), 
                format: FfiConverterString.read(from: &buf), 
                imageUrl: FfiConverterString.read(from: &buf), 
                name: FfiConverterString.read(from: &buf), 
                url: FfiConverterString.read(from: &buf)
        )
    }

    public static func write(_ value: MozAdsTile, into buf: inout [UInt8]) {
        FfiConverterString.write(value.blockKey, into: &buf)
        FfiConverterTypeMozAdsCallbacks.write(value.callbacks, into: &buf)
        FfiConverterString.write(value.format, into: &buf)
        FfiConverterString.write(value.imageUrl, into: &buf)
        FfiConverterString.write(value.name, into: &buf)
        FfiConverterString.write(value.url, into: &buf)
    }
}


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

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

// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.

public enum MozAdsCacheMode {
    
    case cacheFirst
    case networkFirst
}


#if compiler(>=6)
extension MozAdsCacheMode: Sendable {}
#endif

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsCacheMode: FfiConverterRustBuffer {
    typealias SwiftType = MozAdsCacheMode

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsCacheMode {
        let variant: Int32 = try readInt(&buf)
        switch variant {
        
        case 1: return .cacheFirst
        
        case 2: return .networkFirst
        
        default: throw UniffiInternalError.unexpectedEnumCase
        }
    }

    public static func write(_ value: MozAdsCacheMode, into buf: inout [UInt8]) {
        switch value {
        
        
        case .cacheFirst:
            writeInt(&buf, Int32(1))
        
        
        case .networkFirst:
            writeInt(&buf, Int32(2))
        
        }
    }
}


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

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


extension MozAdsCacheMode: Equatable, Hashable {}







public enum MozAdsClientApiError: Swift.Error {

    
    
    case Other(reason: String
    )
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsClientApiError: FfiConverterRustBuffer {
    typealias SwiftType = MozAdsClientApiError

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsClientApiError {
        let variant: Int32 = try readInt(&buf)
        switch variant {

        

        
        case 1: return .Other(
            reason: try FfiConverterString.read(from: &buf)
            )

         default: throw UniffiInternalError.unexpectedEnumCase
        }
    }

    public static func write(_ value: MozAdsClientApiError, into buf: inout [UInt8]) {
        switch value {

        

        
        
        case let .Other(reason):
            writeInt(&buf, Int32(1))
            FfiConverterString.write(reason, into: &buf)
            
        }
    }
}


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

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


extension MozAdsClientApiError: Equatable, Hashable {}




extension MozAdsClientApiError: Foundation.LocalizedError {
    public var errorDescription: String? {
        String(reflecting: self)
    }
}




// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.

public enum MozAdsEnvironment {
    
    case prod
}


#if compiler(>=6)
extension MozAdsEnvironment: Sendable {}
#endif

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsEnvironment: FfiConverterRustBuffer {
    typealias SwiftType = MozAdsEnvironment

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsEnvironment {
        let variant: Int32 = try readInt(&buf)
        switch variant {
        
        case 1: return .prod
        
        default: throw UniffiInternalError.unexpectedEnumCase
        }
    }

    public static func write(_ value: MozAdsEnvironment, into buf: inout [UInt8]) {
        switch value {
        
        
        case .prod:
            writeInt(&buf, Int32(1))
        
        }
    }
}


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

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


extension MozAdsEnvironment: Equatable, Hashable {}






// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.

public enum MozAdsIabContentTaxonomy {
    
    case iab10
    case iab20
    case iab21
    case iab22
    case iab30
}


#if compiler(>=6)
extension MozAdsIabContentTaxonomy: Sendable {}
#endif

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsIABContentTaxonomy: FfiConverterRustBuffer {
    typealias SwiftType = MozAdsIabContentTaxonomy

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsIabContentTaxonomy {
        let variant: Int32 = try readInt(&buf)
        switch variant {
        
        case 1: return .iab10
        
        case 2: return .iab20
        
        case 3: return .iab21
        
        case 4: return .iab22
        
        case 5: return .iab30
        
        default: throw UniffiInternalError.unexpectedEnumCase
        }
    }

    public static func write(_ value: MozAdsIabContentTaxonomy, into buf: inout [UInt8]) {
        switch value {
        
        
        case .iab10:
            writeInt(&buf, Int32(1))
        
        
        case .iab20:
            writeInt(&buf, Int32(2))
        
        
        case .iab21:
            writeInt(&buf, Int32(3))
        
        
        case .iab22:
            writeInt(&buf, Int32(4))
        
        
        case .iab30:
            writeInt(&buf, Int32(5))
        
        }
    }
}


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

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


extension MozAdsIabContentTaxonomy: Equatable, Hashable {}






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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringUInt32: FfiConverterRustBuffer {
    public static func write(_ value: [String: UInt32], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for (key, value) in value {
            FfiConverterString.write(key, into: &buf)
            FfiConverterUInt32.write(value, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: UInt32] {
        let len: Int32 = try readInt(&buf)
        var dict = [String: UInt32]()
        dict.reserveCapacity(Int(len))
        for _ in 0..<len {
            let key = try FfiConverterString.read(from: &buf)
            let value = try FfiConverterUInt32.read(from: &buf)
            dict[key] = value
        }
        return dict
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringTypeMozAdsImage: FfiConverterRustBuffer {
    public static func write(_ value: [String: MozAdsImage], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for (key, value) in value {
            FfiConverterString.write(key, into: &buf)
            FfiConverterTypeMozAdsImage.write(value, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: MozAdsImage] {
        let len: Int32 = try readInt(&buf)
        var dict = [String: MozAdsImage]()
        dict.reserveCapacity(Int(len))
        for _ in 0..<len {
            let key = try FfiConverterString.read(from: &buf)
            let value = try FfiConverterTypeMozAdsImage.read(from: &buf)
            dict[key] = value
        }
        return dict
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringTypeMozAdsTile: FfiConverterRustBuffer {
    public static func write(_ value: [String: MozAdsTile], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for (key, value) in value {
            FfiConverterString.write(key, into: &buf)
            FfiConverterTypeMozAdsTile.write(value, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: MozAdsTile] {
        let len: Int32 = try readInt(&buf)
        var dict = [String: MozAdsTile]()
        dict.reserveCapacity(Int(len))
        for _ in 0..<len {
            let key = try FfiConverterString.read(from: &buf)
            let value = try FfiConverterTypeMozAdsTile.read(from: &buf)
            dict[key] = value
        }
        return dict
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringSequenceTypeMozAdsSpoc: FfiConverterRustBuffer {
    public static func write(_ value: [String: [MozAdsSpoc]], into buf: inout [UInt8]) {
        let len = Int32(value.count)
        writeInt(&buf, len)
        for (key, value) in value {
            FfiConverterString.write(key, into: &buf)
            FfiConverterSequenceTypeMozAdsSpoc.write(value, into: &buf)
        }
    }

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: [MozAdsSpoc]] {
        let len: Int32 = try readInt(&buf)
        var dict = [String: [MozAdsSpoc]]()
        dict.reserveCapacity(Int(len))
        for _ in 0..<len {
            let key = try FfiConverterString.read(from: &buf)
            let value = try FfiConverterSequenceTypeMozAdsSpoc.read(from: &buf)
            dict[key] = value
        }
        return dict
    }
}


/**
 * Typealias from the type name used in the UDL file to the builtin type.  This
 * is needed because the UDL type name is used in function/method signatures.
 */
public typealias AdsClientUrl = String

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeAdsClientUrl: FfiConverter {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AdsClientUrl {
        return try FfiConverterString.read(from: &buf)
    }

    public static func write(_ value: AdsClientUrl, into buf: inout [UInt8]) {
        return FfiConverterString.write(value, into: &buf)
    }

    public static func lift(_ value: RustBuffer) throws -> AdsClientUrl {
        return try FfiConverterString.lift(value)
    }

    public static func lower(_ value: AdsClientUrl) -> RustBuffer {
        return FfiConverterString.lower(value)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAdsClientUrl_lift(_ value: RustBuffer) throws -> AdsClientUrl {
    return try FfiConverterTypeAdsClientUrl.lift(value)
}

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


private enum InitializationResult {
    case ok
    case contractVersionMismatch
    case apiChecksumMismatch
}
// Use a global variable to perform the versioning checks. Swift ensures that
// the code inside is only computed once.
private let initializationResult: InitializationResult = {
    // Get the bindings contract version from our ComponentInterface
    let bindings_contract_version = 29
    // Get the scaffolding contract version by calling the into the dylib
    let scaffolding_contract_version = ffi_ads_client_uniffi_contract_version()
    if bindings_contract_version != scaffolding_contract_version {
        return InitializationResult.contractVersionMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadsclient_clear_cache() != 10370) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadsclient_cycle_context_id() != 12333) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadsclient_record_click() != 17646) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadsclient_record_impression() != 28013) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadsclient_report_ad() != 17071) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadsclient_request_image_ads() != 5900) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadsclient_request_spoc_ads() != 60345) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadsclient_request_tile_ads() != 57621) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadstelemetry_record_build_cache_error() != 16257) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadstelemetry_record_client_error() != 13788) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadstelemetry_record_client_operation_total() != 61968) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadstelemetry_record_deserialization_error() != 17062) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_method_mozadstelemetry_record_http_cache_outcome() != 51965) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_ads_client_checksum_constructor_mozadsclient_new() != 17901) {
        return InitializationResult.apiChecksumMismatch
    }

    uniffiCallbackInitMozAdsTelemetry()
    return InitializationResult.ok
}()

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

// swiftlint:enable all