// 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(VitalLensCoreFFI)
import VitalLensCoreFFI
#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_vitallens_core_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_vitallens_core_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 {
    uniffiEnsureInitialized()
    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 class UniffiHandleMap<T> {
    private var map: [UInt64: T] = [:]
    private let lock = NSLock()
    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.


#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 FfiConverterFloat: FfiConverterPrimitive {
    typealias FfiType = Float
    typealias SwiftType = Float

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

    public static func write(_ value: Float, into buf: inout [UInt8]) {
        writeFloat(&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 FfiConverterBool : FfiConverter {
    typealias FfiType = Int8
    typealias SwiftType = Bool

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

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

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

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

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

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

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

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

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




/**
 * Manages the tracking, matching, and lifecycle of video frame buffers across a session.
 */
public protocol BufferPlannerProtocol : AnyObject {
    
    /**
     * Evaluates a target ROI against the list of known active buffers using
     * Intersection over Union (IoU) to maintain spatial consistency.
     *
     * # Arguments
     * * `target_roi` - The bounding box of the newly detected subject.
     * * `timestamp` - The current frame's timestamp.
     * * `active_buffers` - Metadata of currently tracked buffers.
     *
     * # Returns
     * A `BufferAction` instructing the caller to either append to an existing buffer or create a new one.
     */
    func evaluateTarget(targetRoi: Rect, timestamp: Double, activeBuffers: [BufferMetadata])  -> BufferAction
    
    /**
     * Determines if a specific buffer is actionable based on volume and configuration constraints.
     */
    func isReady(count: UInt32, mode: InferenceMode, hasState: Bool, flush: Bool)  -> Bool
    
    /**
     * Determines which buffer (if any) is ready for inference execution, and identifies
     * stale buffers that should be dropped from memory.
     *
     * # Arguments
     * * `active_buffers` - Metadata of currently tracked buffers.
     * * `current_time` - The current execution timestamp.
     * * `mode` - The operational mode (Stream or File).
     * * `has_state` - Whether the engine has warmed up with prior state.
     * * `flush` - If true, forces the consumption of the buffer regardless of capacity limits.
     *
     * # Returns
     * An `ExecutionPlan` containing an optional command to execute inference, and a list of buffer IDs to drop.
     */
    func poll(activeBuffers: [BufferMetadata], currentTime: Double, mode: InferenceMode, hasState: Bool, flush: Bool)  -> ExecutionPlan
    
}

/**
 * Manages the tracking, matching, and lifecycle of video frame buffers across a session.
 */
open class BufferPlanner:
    BufferPlannerProtocol {
    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`.
    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_vitallens_core_fn_clone_bufferplanner(self.pointer, $0) }
    }
public convenience init(config: BufferConfig) {
    let pointer =
        try! rustCall() {
    uniffi_vitallens_core_fn_constructor_bufferplanner_new(
        FfiConverterTypeBufferConfig.lower(config),$0
    )
}
    self.init(unsafeFromRawPointer: pointer)
}

    deinit {
        guard let pointer = pointer else {
            return
        }

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

    

    
    /**
     * Evaluates a target ROI against the list of known active buffers using
     * Intersection over Union (IoU) to maintain spatial consistency.
     *
     * # Arguments
     * * `target_roi` - The bounding box of the newly detected subject.
     * * `timestamp` - The current frame's timestamp.
     * * `active_buffers` - Metadata of currently tracked buffers.
     *
     * # Returns
     * A `BufferAction` instructing the caller to either append to an existing buffer or create a new one.
     */
open func evaluateTarget(targetRoi: Rect, timestamp: Double, activeBuffers: [BufferMetadata]) -> BufferAction {
    return try!  FfiConverterTypeBufferAction.lift(try! rustCall() {
    uniffi_vitallens_core_fn_method_bufferplanner_evaluate_target(self.uniffiClonePointer(),
        FfiConverterTypeRect.lower(targetRoi),
        FfiConverterDouble.lower(timestamp),
        FfiConverterSequenceTypeBufferMetadata.lower(activeBuffers),$0
    )
})
}
    
    /**
     * Determines if a specific buffer is actionable based on volume and configuration constraints.
     */
open func isReady(count: UInt32, mode: InferenceMode, hasState: Bool, flush: Bool) -> Bool {
    return try!  FfiConverterBool.lift(try! rustCall() {
    uniffi_vitallens_core_fn_method_bufferplanner_is_ready(self.uniffiClonePointer(),
        FfiConverterUInt32.lower(count),
        FfiConverterTypeInferenceMode.lower(mode),
        FfiConverterBool.lower(hasState),
        FfiConverterBool.lower(flush),$0
    )
})
}
    
    /**
     * Determines which buffer (if any) is ready for inference execution, and identifies
     * stale buffers that should be dropped from memory.
     *
     * # Arguments
     * * `active_buffers` - Metadata of currently tracked buffers.
     * * `current_time` - The current execution timestamp.
     * * `mode` - The operational mode (Stream or File).
     * * `has_state` - Whether the engine has warmed up with prior state.
     * * `flush` - If true, forces the consumption of the buffer regardless of capacity limits.
     *
     * # Returns
     * An `ExecutionPlan` containing an optional command to execute inference, and a list of buffer IDs to drop.
     */
open func poll(activeBuffers: [BufferMetadata], currentTime: Double, mode: InferenceMode, hasState: Bool, flush: Bool) -> ExecutionPlan {
    return try!  FfiConverterTypeExecutionPlan.lift(try! rustCall() {
    uniffi_vitallens_core_fn_method_bufferplanner_poll(self.uniffiClonePointer(),
        FfiConverterSequenceTypeBufferMetadata.lower(activeBuffers),
        FfiConverterDouble.lower(currentTime),
        FfiConverterTypeInferenceMode.lower(mode),
        FfiConverterBool.lower(hasState),
        FfiConverterBool.lower(flush),$0
    )
})
}
    

}

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

    typealias FfiType = UnsafeMutableRawPointer
    typealias SwiftType = BufferPlanner

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

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

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BufferPlanner {
        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: BufferPlanner, 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 FfiConverterTypeBufferPlanner_lift(_ pointer: UnsafeMutableRawPointer) throws -> BufferPlanner {
    return try FfiConverterTypeBufferPlanner.lift(pointer)
}

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




/**
 * A thread-safe, stateful session object for processing continuous frame data natively across FFI and Wasm.
 */
public protocol SessionProtocol : AnyObject {
    
    /**
     * Processes a new batch of inputs, updating the session's internal state
     * and returning the calculated vital signs and waveforms.
     *
     * # Arguments
     * * `input` - The latest batch of input data (signals, face coordinates, timestamps).
     * * `mode` - The extraction mode dictating the payload size (Incremental, Windowed, or Global).
     *
     * # Returns
     * A `SessionResult` containing the estimated vitals, waveforms, and metadata.
     */
    func process(input: SessionInput, mode: WaveformMode)  -> SessionResult
    
    /**
     * Resets the internal state of the session, clearing all historical buffers.
     */
    func reset() 
    
}

/**
 * A thread-safe, stateful session object for processing continuous frame data natively across FFI and Wasm.
 */
open class Session:
    SessionProtocol {
    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`.
    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_vitallens_core_fn_clone_session(self.pointer, $0) }
    }
    /**
     * Creates a new stateful session using the provided configuration.
     *
     * # Arguments
     * * `config` - The configuration parameters dictating target frame rate and model metadata.
     *
     * # Returns
     * A new instance of `Session`.
     */
public convenience init(config: SessionConfig) {
    let pointer =
        try! rustCall() {
    uniffi_vitallens_core_fn_constructor_session_new(
        FfiConverterTypeSessionConfig.lower(config),$0
    )
}
    self.init(unsafeFromRawPointer: pointer)
}

    deinit {
        guard let pointer = pointer else {
            return
        }

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

    

    
    /**
     * Processes a new batch of inputs, updating the session's internal state
     * and returning the calculated vital signs and waveforms.
     *
     * # Arguments
     * * `input` - The latest batch of input data (signals, face coordinates, timestamps).
     * * `mode` - The extraction mode dictating the payload size (Incremental, Windowed, or Global).
     *
     * # Returns
     * A `SessionResult` containing the estimated vitals, waveforms, and metadata.
     */
open func process(input: SessionInput, mode: WaveformMode) -> SessionResult {
    return try!  FfiConverterTypeSessionResult.lift(try! rustCall() {
    uniffi_vitallens_core_fn_method_session_process(self.uniffiClonePointer(),
        FfiConverterTypeSessionInput.lower(input),
        FfiConverterTypeWaveformMode.lower(mode),$0
    )
})
}
    
    /**
     * Resets the internal state of the session, clearing all historical buffers.
     */
open func reset() {try! rustCall() {
    uniffi_vitallens_core_fn_method_session_reset(self.uniffiClonePointer(),$0
    )
}
}
    

}

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

    typealias FfiType = UnsafeMutableRawPointer
    typealias SwiftType = Session

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

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

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Session {
        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: Session, 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 FfiConverterTypeSession_lift(_ pointer: UnsafeMutableRawPointer) throws -> Session {
    return try FfiConverterTypeSession.lift(pointer)
}

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


/**
 * The concrete instruction resulting from evaluating a target.
 */
public struct BufferAction {
    public var action: BufferActionType
    public var matchedId: String?
    public var roi: Rect?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(action: BufferActionType, matchedId: String?, roi: Rect?) {
        self.action = action
        self.matchedId = matchedId
        self.roi = roi
    }
}



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

    public func hash(into hasher: inout Hasher) {
        hasher.combine(action)
        hasher.combine(matchedId)
        hasher.combine(roi)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeBufferAction: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BufferAction {
        return
            try BufferAction(
                action: FfiConverterTypeBufferActionType.read(from: &buf), 
                matchedId: FfiConverterOptionString.read(from: &buf), 
                roi: FfiConverterOptionTypeRect.read(from: &buf)
        )
    }

    public static func write(_ value: BufferAction, into buf: inout [UInt8]) {
        FfiConverterTypeBufferActionType.write(value.action, into: &buf)
        FfiConverterOptionString.write(value.matchedId, into: &buf)
        FfiConverterOptionTypeRect.write(value.roi, into: &buf)
    }
}


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

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


/**
 * Capacity constraints and threshold configuration for buffers.
 */
public struct BufferConfig {
    public var minNoState: UInt32
    public var minWithState: UInt32
    public var streamMax: UInt32
    public var fileMax: UInt32
    public var overlap: UInt32

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(minNoState: UInt32, minWithState: UInt32, streamMax: UInt32, fileMax: UInt32, overlap: UInt32) {
        self.minNoState = minNoState
        self.minWithState = minWithState
        self.streamMax = streamMax
        self.fileMax = fileMax
        self.overlap = overlap
    }
}



extension BufferConfig: Equatable, Hashable {
    public static func ==(lhs: BufferConfig, rhs: BufferConfig) -> Bool {
        if lhs.minNoState != rhs.minNoState {
            return false
        }
        if lhs.minWithState != rhs.minWithState {
            return false
        }
        if lhs.streamMax != rhs.streamMax {
            return false
        }
        if lhs.fileMax != rhs.fileMax {
            return false
        }
        if lhs.overlap != rhs.overlap {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(minNoState)
        hasher.combine(minWithState)
        hasher.combine(streamMax)
        hasher.combine(fileMax)
        hasher.combine(overlap)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeBufferConfig: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BufferConfig {
        return
            try BufferConfig(
                minNoState: FfiConverterUInt32.read(from: &buf), 
                minWithState: FfiConverterUInt32.read(from: &buf), 
                streamMax: FfiConverterUInt32.read(from: &buf), 
                fileMax: FfiConverterUInt32.read(from: &buf), 
                overlap: FfiConverterUInt32.read(from: &buf)
        )
    }

    public static func write(_ value: BufferConfig, into buf: inout [UInt8]) {
        FfiConverterUInt32.write(value.minNoState, into: &buf)
        FfiConverterUInt32.write(value.minWithState, into: &buf)
        FfiConverterUInt32.write(value.streamMax, into: &buf)
        FfiConverterUInt32.write(value.fileMax, into: &buf)
        FfiConverterUInt32.write(value.overlap, into: &buf)
    }
}


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

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


/**
 * Identifiable state metadata attached to a specific processing buffer.
 */
public struct BufferMetadata {
    public var id: String
    public var roi: Rect
    public var count: UInt32
    public var createdAt: Double
    public var lastSeen: Double

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(id: String, roi: Rect, count: UInt32, createdAt: Double, lastSeen: Double) {
        self.id = id
        self.roi = roi
        self.count = count
        self.createdAt = createdAt
        self.lastSeen = lastSeen
    }
}



extension BufferMetadata: Equatable, Hashable {
    public static func ==(lhs: BufferMetadata, rhs: BufferMetadata) -> Bool {
        if lhs.id != rhs.id {
            return false
        }
        if lhs.roi != rhs.roi {
            return false
        }
        if lhs.count != rhs.count {
            return false
        }
        if lhs.createdAt != rhs.createdAt {
            return false
        }
        if lhs.lastSeen != rhs.lastSeen {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(id)
        hasher.combine(roi)
        hasher.combine(count)
        hasher.combine(createdAt)
        hasher.combine(lastSeen)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeBufferMetadata: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BufferMetadata {
        return
            try BufferMetadata(
                id: FfiConverterString.read(from: &buf), 
                roi: FfiConverterTypeRect.read(from: &buf), 
                count: FfiConverterUInt32.read(from: &buf), 
                createdAt: FfiConverterDouble.read(from: &buf), 
                lastSeen: FfiConverterDouble.read(from: &buf)
        )
    }

    public static func write(_ value: BufferMetadata, into buf: inout [UInt8]) {
        FfiConverterString.write(value.id, into: &buf)
        FfiConverterTypeRect.write(value.roi, into: &buf)
        FfiConverterUInt32.write(value.count, into: &buf)
        FfiConverterDouble.write(value.createdAt, into: &buf)
        FfiConverterDouble.write(value.lastSeen, into: &buf)
    }
}


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

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


/**
 * Aggregated output from the BufferPlanner dictating next steps for all buffers.
 */
public struct ExecutionPlan {
    public var command: InferenceCommand?
    public var buffersToDrop: [String]

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(command: InferenceCommand?, buffersToDrop: [String]) {
        self.command = command
        self.buffersToDrop = buffersToDrop
    }
}



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

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


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeExecutionPlan: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ExecutionPlan {
        return
            try ExecutionPlan(
                command: FfiConverterOptionTypeInferenceCommand.read(from: &buf), 
                buffersToDrop: FfiConverterSequenceString.read(from: &buf)
        )
    }

    public static func write(_ value: ExecutionPlan, into buf: inout [UInt8]) {
        FfiConverterOptionTypeInferenceCommand.write(value.command, into: &buf)
        FfiConverterSequenceString.write(value.buffersToDrop, into: &buf)
    }
}


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

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


/**
 * Input payload representing tracked face bounding boxes over a sequence of frames.
 */
public struct FaceInput {
    public var coordinates: [[Float]]
    public var confidence: [Float]

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(coordinates: [[Float]], confidence: [Float]) {
        self.coordinates = coordinates
        self.confidence = confidence
    }
}



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

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


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFaceInput: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FaceInput {
        return
            try FaceInput(
                coordinates: FfiConverterSequenceSequenceFloat.read(from: &buf), 
                confidence: FfiConverterSequenceFloat.read(from: &buf)
        )
    }

    public static func write(_ value: FaceInput, into buf: inout [UInt8]) {
        FfiConverterSequenceSequenceFloat.write(value.coordinates, into: &buf)
        FfiConverterSequenceFloat.write(value.confidence, into: &buf)
    }
}


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

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


/**
 * Filtered/smoothed output face coordinates.
 */
public struct FaceResult {
    public var coordinates: [[Float]]
    public var confidence: [Float]
    public var note: String?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(coordinates: [[Float]], confidence: [Float], note: String?) {
        self.coordinates = coordinates
        self.confidence = confidence
        self.note = note
    }
}



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

    public func hash(into hasher: inout Hasher) {
        hasher.combine(coordinates)
        hasher.combine(confidence)
        hasher.combine(note)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFaceResult: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FaceResult {
        return
            try FaceResult(
                coordinates: FfiConverterSequenceSequenceFloat.read(from: &buf), 
                confidence: FfiConverterSequenceFloat.read(from: &buf), 
                note: FfiConverterOptionString.read(from: &buf)
        )
    }

    public static func write(_ value: FaceResult, into buf: inout [UInt8]) {
        FfiConverterSequenceSequenceFloat.write(value.coordinates, into: &buf)
        FfiConverterSequenceFloat.write(value.confidence, into: &buf)
        FfiConverterOptionString.write(value.note, into: &buf)
    }
}


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

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


/**
 * Command returned by the BufferPlanner indicating how many frames to extract.
 */
public struct InferenceCommand {
    public var bufferId: String
    public var takeCount: UInt32
    public var keepCount: UInt32

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



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

    public func hash(into hasher: inout Hasher) {
        hasher.combine(bufferId)
        hasher.combine(takeCount)
        hasher.combine(keepCount)
    }
}


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

    public static func write(_ value: InferenceCommand, into buf: inout [UInt8]) {
        FfiConverterString.write(value.bufferId, into: &buf)
        FfiConverterUInt32.write(value.takeCount, into: &buf)
        FfiConverterUInt32.write(value.keepCount, into: &buf)
    }
}


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

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


/**
 * A simple bounding box definition.
 */
public struct Rect {
    public var x: Float
    public var y: Float
    public var width: Float
    public var height: Float

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(x: Float, y: Float, width: Float, height: Float) {
        self.x = x
        self.y = y
        self.width = width
        self.height = height
    }
}



extension Rect: Equatable, Hashable {
    public static func ==(lhs: Rect, rhs: Rect) -> Bool {
        if lhs.x != rhs.x {
            return false
        }
        if lhs.y != rhs.y {
            return false
        }
        if lhs.width != rhs.width {
            return false
        }
        if lhs.height != rhs.height {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(x)
        hasher.combine(y)
        hasher.combine(width)
        hasher.combine(height)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeRect: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Rect {
        return
            try Rect(
                x: FfiConverterFloat.read(from: &buf), 
                y: FfiConverterFloat.read(from: &buf), 
                width: FfiConverterFloat.read(from: &buf), 
                height: FfiConverterFloat.read(from: &buf)
        )
    }

    public static func write(_ value: Rect, into buf: inout [UInt8]) {
        FfiConverterFloat.write(value.x, into: &buf)
        FfiConverterFloat.write(value.y, into: &buf)
        FfiConverterFloat.write(value.width, into: &buf)
        FfiConverterFloat.write(value.height, into: &buf)
    }
}


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

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


/**
 * Configuration for initializing a VitalLens session.
 */
public struct SessionConfig {
    public var modelName: String
    public var supportedVitals: [String]
    public var returnWaveforms: [String]?
    public var fpsTarget: Float
    public var inputSize: UInt64
    public var nInputs: UInt64
    public var roiMethod: String
    public var estimateRollingVitals: Bool?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(modelName: String, supportedVitals: [String], returnWaveforms: [String]?, fpsTarget: Float, inputSize: UInt64, nInputs: UInt64, roiMethod: String, estimateRollingVitals: Bool? = nil) {
        self.modelName = modelName
        self.supportedVitals = supportedVitals
        self.returnWaveforms = returnWaveforms
        self.fpsTarget = fpsTarget
        self.inputSize = inputSize
        self.nInputs = nInputs
        self.roiMethod = roiMethod
        self.estimateRollingVitals = estimateRollingVitals
    }
}



extension SessionConfig: Equatable, Hashable {
    public static func ==(lhs: SessionConfig, rhs: SessionConfig) -> Bool {
        if lhs.modelName != rhs.modelName {
            return false
        }
        if lhs.supportedVitals != rhs.supportedVitals {
            return false
        }
        if lhs.returnWaveforms != rhs.returnWaveforms {
            return false
        }
        if lhs.fpsTarget != rhs.fpsTarget {
            return false
        }
        if lhs.inputSize != rhs.inputSize {
            return false
        }
        if lhs.nInputs != rhs.nInputs {
            return false
        }
        if lhs.roiMethod != rhs.roiMethod {
            return false
        }
        if lhs.estimateRollingVitals != rhs.estimateRollingVitals {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(modelName)
        hasher.combine(supportedVitals)
        hasher.combine(returnWaveforms)
        hasher.combine(fpsTarget)
        hasher.combine(inputSize)
        hasher.combine(nInputs)
        hasher.combine(roiMethod)
        hasher.combine(estimateRollingVitals)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeSessionConfig: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SessionConfig {
        return
            try SessionConfig(
                modelName: FfiConverterString.read(from: &buf), 
                supportedVitals: FfiConverterSequenceString.read(from: &buf), 
                returnWaveforms: FfiConverterOptionSequenceString.read(from: &buf), 
                fpsTarget: FfiConverterFloat.read(from: &buf), 
                inputSize: FfiConverterUInt64.read(from: &buf), 
                nInputs: FfiConverterUInt64.read(from: &buf), 
                roiMethod: FfiConverterString.read(from: &buf), 
                estimateRollingVitals: FfiConverterOptionBool.read(from: &buf)
        )
    }

    public static func write(_ value: SessionConfig, into buf: inout [UInt8]) {
        FfiConverterString.write(value.modelName, into: &buf)
        FfiConverterSequenceString.write(value.supportedVitals, into: &buf)
        FfiConverterOptionSequenceString.write(value.returnWaveforms, into: &buf)
        FfiConverterFloat.write(value.fpsTarget, into: &buf)
        FfiConverterUInt64.write(value.inputSize, into: &buf)
        FfiConverterUInt64.write(value.nInputs, into: &buf)
        FfiConverterString.write(value.roiMethod, into: &buf)
        FfiConverterOptionBool.write(value.estimateRollingVitals, into: &buf)
    }
}


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

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


/**
 * The core batch input object submitted to the session engine for processing.
 */
public struct SessionInput {
    public var face: FaceInput?
    public var signals: [String: SignalInput]
    public var timestamp: [Double]

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(face: FaceInput?, signals: [String: SignalInput], timestamp: [Double]) {
        self.face = face
        self.signals = signals
        self.timestamp = timestamp
    }
}



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

    public func hash(into hasher: inout Hasher) {
        hasher.combine(face)
        hasher.combine(signals)
        hasher.combine(timestamp)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeSessionInput: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SessionInput {
        return
            try SessionInput(
                face: FfiConverterOptionTypeFaceInput.read(from: &buf), 
                signals: FfiConverterDictionaryStringTypeSignalInput.read(from: &buf), 
                timestamp: FfiConverterSequenceDouble.read(from: &buf)
        )
    }

    public static func write(_ value: SessionInput, into buf: inout [UInt8]) {
        FfiConverterOptionTypeFaceInput.write(value.face, into: &buf)
        FfiConverterDictionaryStringTypeSignalInput.write(value.signals, into: &buf)
        FfiConverterSequenceDouble.write(value.timestamp, into: &buf)
    }
}


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

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


/**
 * The final payload aggregated from a session processing tick.
 */
public struct SessionResult {
    public var timestamp: [Double]
    public var face: FaceResult?
    public var waveforms: [String: WaveformResult]
    public var vitals: [String: VitalResult]
    public var rollingVitals: [String: WaveformResult]?
    public var fps: Float
    public var message: String

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(timestamp: [Double], face: FaceResult?, waveforms: [String: WaveformResult], vitals: [String: VitalResult], rollingVitals: [String: WaveformResult]?, fps: Float, message: String) {
        self.timestamp = timestamp
        self.face = face
        self.waveforms = waveforms
        self.vitals = vitals
        self.rollingVitals = rollingVitals
        self.fps = fps
        self.message = message
    }
}



extension SessionResult: Equatable, Hashable {
    public static func ==(lhs: SessionResult, rhs: SessionResult) -> Bool {
        if lhs.timestamp != rhs.timestamp {
            return false
        }
        if lhs.face != rhs.face {
            return false
        }
        if lhs.waveforms != rhs.waveforms {
            return false
        }
        if lhs.vitals != rhs.vitals {
            return false
        }
        if lhs.rollingVitals != rhs.rollingVitals {
            return false
        }
        if lhs.fps != rhs.fps {
            return false
        }
        if lhs.message != rhs.message {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(timestamp)
        hasher.combine(face)
        hasher.combine(waveforms)
        hasher.combine(vitals)
        hasher.combine(rollingVitals)
        hasher.combine(fps)
        hasher.combine(message)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeSessionResult: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SessionResult {
        return
            try SessionResult(
                timestamp: FfiConverterSequenceDouble.read(from: &buf), 
                face: FfiConverterOptionTypeFaceResult.read(from: &buf), 
                waveforms: FfiConverterDictionaryStringTypeWaveformResult.read(from: &buf), 
                vitals: FfiConverterDictionaryStringTypeVitalResult.read(from: &buf), 
                rollingVitals: FfiConverterOptionDictionaryStringTypeWaveformResult.read(from: &buf), 
                fps: FfiConverterFloat.read(from: &buf), 
                message: FfiConverterString.read(from: &buf)
        )
    }

    public static func write(_ value: SessionResult, into buf: inout [UInt8]) {
        FfiConverterSequenceDouble.write(value.timestamp, into: &buf)
        FfiConverterOptionTypeFaceResult.write(value.face, into: &buf)
        FfiConverterDictionaryStringTypeWaveformResult.write(value.waveforms, into: &buf)
        FfiConverterDictionaryStringTypeVitalResult.write(value.vitals, into: &buf)
        FfiConverterOptionDictionaryStringTypeWaveformResult.write(value.rollingVitals, into: &buf)
        FfiConverterFloat.write(value.fps, into: &buf)
        FfiConverterString.write(value.message, into: &buf)
    }
}


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

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


/**
 * A generic wrapper for a single physical signal and its corresponding confidence array.
 */
public struct SignalInput {
    public var data: [Float]
    public var confidence: [Float]

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(data: [Float], confidence: [Float]) {
        self.data = data
        self.confidence = confidence
    }
}



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

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


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

    public static func write(_ value: SignalInput, into buf: inout [UInt8]) {
        FfiConverterSequenceFloat.write(value.data, into: &buf)
        FfiConverterSequenceFloat.write(value.confidence, into: &buf)
    }
}


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

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


/**
 * Extracted UI/display properties for a specific vital sign.
 */
public struct VitalDisplayMeta {
    public var id: String
    public var displayName: String
    public var shortName: String
    public var unit: String
    public var color: String
    public var emoji: String

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(id: String, displayName: String, shortName: String, unit: String, color: String, emoji: String) {
        self.id = id
        self.displayName = displayName
        self.shortName = shortName
        self.unit = unit
        self.color = color
        self.emoji = emoji
    }
}



extension VitalDisplayMeta: Equatable, Hashable {
    public static func ==(lhs: VitalDisplayMeta, rhs: VitalDisplayMeta) -> Bool {
        if lhs.id != rhs.id {
            return false
        }
        if lhs.displayName != rhs.displayName {
            return false
        }
        if lhs.shortName != rhs.shortName {
            return false
        }
        if lhs.unit != rhs.unit {
            return false
        }
        if lhs.color != rhs.color {
            return false
        }
        if lhs.emoji != rhs.emoji {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(id)
        hasher.combine(displayName)
        hasher.combine(shortName)
        hasher.combine(unit)
        hasher.combine(color)
        hasher.combine(emoji)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeVitalDisplayMeta: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> VitalDisplayMeta {
        return
            try VitalDisplayMeta(
                id: FfiConverterString.read(from: &buf), 
                displayName: FfiConverterString.read(from: &buf), 
                shortName: FfiConverterString.read(from: &buf), 
                unit: FfiConverterString.read(from: &buf), 
                color: FfiConverterString.read(from: &buf), 
                emoji: FfiConverterString.read(from: &buf)
        )
    }

    public static func write(_ value: VitalDisplayMeta, into buf: inout [UInt8]) {
        FfiConverterString.write(value.id, into: &buf)
        FfiConverterString.write(value.displayName, into: &buf)
        FfiConverterString.write(value.shortName, into: &buf)
        FfiConverterString.write(value.unit, into: &buf)
        FfiConverterString.write(value.color, into: &buf)
        FfiConverterString.write(value.emoji, into: &buf)
    }
}


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

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


/**
 * Derived scalar physiological value.
 */
public struct VitalResult {
    public var value: Float
    public var confidence: Float
    public var unit: String
    public var note: String

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(value: Float, confidence: Float, unit: String, note: String) {
        self.value = value
        self.confidence = confidence
        self.unit = unit
        self.note = note
    }
}



extension VitalResult: Equatable, Hashable {
    public static func ==(lhs: VitalResult, rhs: VitalResult) -> Bool {
        if lhs.value != rhs.value {
            return false
        }
        if lhs.confidence != rhs.confidence {
            return false
        }
        if lhs.unit != rhs.unit {
            return false
        }
        if lhs.note != rhs.note {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(value)
        hasher.combine(confidence)
        hasher.combine(unit)
        hasher.combine(note)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeVitalResult: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> VitalResult {
        return
            try VitalResult(
                value: FfiConverterFloat.read(from: &buf), 
                confidence: FfiConverterFloat.read(from: &buf), 
                unit: FfiConverterString.read(from: &buf), 
                note: FfiConverterString.read(from: &buf)
        )
    }

    public static func write(_ value: VitalResult, into buf: inout [UInt8]) {
        FfiConverterFloat.write(value.value, into: &buf)
        FfiConverterFloat.write(value.confidence, into: &buf)
        FfiConverterString.write(value.unit, into: &buf)
        FfiConverterString.write(value.note, into: &buf)
    }
}


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

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


/**
 * Derived continuous waveform data alongside unit metadata.
 */
public struct WaveformResult {
    public var data: [Float]
    public var confidence: [Float]
    public var unit: String
    public var note: String

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(data: [Float], confidence: [Float], unit: String, note: String) {
        self.data = data
        self.confidence = confidence
        self.unit = unit
        self.note = note
    }
}



extension WaveformResult: Equatable, Hashable {
    public static func ==(lhs: WaveformResult, rhs: WaveformResult) -> Bool {
        if lhs.data != rhs.data {
            return false
        }
        if lhs.confidence != rhs.confidence {
            return false
        }
        if lhs.unit != rhs.unit {
            return false
        }
        if lhs.note != rhs.note {
            return false
        }
        return true
    }

    public func hash(into hasher: inout Hasher) {
        hasher.combine(data)
        hasher.combine(confidence)
        hasher.combine(unit)
        hasher.combine(note)
    }
}


#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeWaveformResult: FfiConverterRustBuffer {
    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> WaveformResult {
        return
            try WaveformResult(
                data: FfiConverterSequenceFloat.read(from: &buf), 
                confidence: FfiConverterSequenceFloat.read(from: &buf), 
                unit: FfiConverterString.read(from: &buf), 
                note: FfiConverterString.read(from: &buf)
        )
    }

    public static func write(_ value: WaveformResult, into buf: inout [UInt8]) {
        FfiConverterSequenceFloat.write(value.data, into: &buf)
        FfiConverterSequenceFloat.write(value.confidence, into: &buf)
        FfiConverterString.write(value.unit, into: &buf)
        FfiConverterString.write(value.note, into: &buf)
    }
}


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

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

// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
/**
 * Action to be taken on a target ROI after evaluation.
 */

public enum BufferActionType {
    
    case create
    case keepAlive
    case ignore
}


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

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

    public static func write(_ value: BufferActionType, into buf: inout [UInt8]) {
        switch value {
        
        
        case .create:
            writeInt(&buf, Int32(1))
        
        
        case .keepAlive:
            writeInt(&buf, Int32(2))
        
        
        case .ignore:
            writeInt(&buf, Int32(3))
        
        }
    }
}


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

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



extension BufferActionType: Equatable, Hashable {}



// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
/**
 * The origin detector format of the incoming bounding box.
 */

public enum FaceDetector {
    
    case `default`
    case appleVision
}


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

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

    public static func write(_ value: FaceDetector, into buf: inout [UInt8]) {
        switch value {
        
        
        case .`default`:
            writeInt(&buf, Int32(1))
        
        
        case .appleVision:
            writeInt(&buf, Int32(2))
        
        }
    }
}


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

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



extension FaceDetector: Equatable, Hashable {}



// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
/**
 * Operational paradigm dictating buffer fill limits.
 */

public enum InferenceMode {
    
    case stream
    case file
}


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

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

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


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

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



extension InferenceMode: Equatable, Hashable {}



// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
/**
 * Pre-defined and custom methods for extracting physical ROIs from a base face bounding box.
 */

public enum RoiMethod {
    
    case face
    case forehead
    case upperBody
    case upperBodyCropped
    case custom(left: Float, top: Float, right: Float, bottom: Float
    )
}


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

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RoiMethod {
        let variant: Int32 = try readInt(&buf)
        switch variant {
        
        case 1: return .face
        
        case 2: return .forehead
        
        case 3: return .upperBody
        
        case 4: return .upperBodyCropped
        
        case 5: return .custom(left: try FfiConverterFloat.read(from: &buf), top: try FfiConverterFloat.read(from: &buf), right: try FfiConverterFloat.read(from: &buf), bottom: try FfiConverterFloat.read(from: &buf)
        )
        
        default: throw UniffiInternalError.unexpectedEnumCase
        }
    }

    public static func write(_ value: RoiMethod, into buf: inout [UInt8]) {
        switch value {
        
        
        case .face:
            writeInt(&buf, Int32(1))
        
        
        case .forehead:
            writeInt(&buf, Int32(2))
        
        
        case .upperBody:
            writeInt(&buf, Int32(3))
        
        
        case .upperBodyCropped:
            writeInt(&buf, Int32(4))
        
        
        case let .custom(left,top,right,bottom):
            writeInt(&buf, Int32(5))
            FfiConverterFloat.write(left, into: &buf)
            FfiConverterFloat.write(top, into: &buf)
            FfiConverterFloat.write(right, into: &buf)
            FfiConverterFloat.write(bottom, into: &buf)
            
        }
    }
}


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

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



extension RoiMethod: Equatable, Hashable {}



// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
/**
 * Dictates how the session should prune state and yield output waveforms.
 */

public enum WaveformMode {
    
    /**
     * Returns only newly added frames, discarding older history.
     */
    case incremental
    /**
     * Returns a fixed trailing window of data (in seconds).
     */
    case windowed(seconds: Float
    )
    /**
     * Returns the entire history and disables state pruning.
     */
    case global
}


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

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> WaveformMode {
        let variant: Int32 = try readInt(&buf)
        switch variant {
        
        case 1: return .incremental
        
        case 2: return .windowed(seconds: try FfiConverterFloat.read(from: &buf)
        )
        
        case 3: return .global
        
        default: throw UniffiInternalError.unexpectedEnumCase
        }
    }

    public static func write(_ value: WaveformMode, into buf: inout [UInt8]) {
        switch value {
        
        
        case .incremental:
            writeInt(&buf, Int32(1))
        
        
        case let .windowed(seconds):
            writeInt(&buf, Int32(2))
            FfiConverterFloat.write(seconds, into: &buf)
            
        
        case .global:
            writeInt(&buf, Int32(3))
        
        }
    }
}


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

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



extension WaveformMode: Equatable, Hashable {}



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

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterFloat.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 FfiConverterFloat.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

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

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterBool.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 FfiConverterBool.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 FfiConverterOptionTypeFaceInput: FfiConverterRustBuffer {
    typealias SwiftType = FaceInput?

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterTypeFaceInput.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 FfiConverterTypeFaceInput.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

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

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterTypeFaceResult.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 FfiConverterTypeFaceResult.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

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

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterTypeInferenceCommand.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 FfiConverterTypeInferenceCommand.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

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

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterTypeRect.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 FfiConverterTypeRect.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

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

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterTypeVitalDisplayMeta.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 FfiConverterTypeVitalDisplayMeta.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionSequenceString: 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))
        FfiConverterSequenceString.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 FfiConverterSequenceString.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

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

    public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
        guard let value = value else {
            writeInt(&buf, Int8(0))
            return
        }
        writeInt(&buf, Int8(1))
        FfiConverterDictionaryStringTypeWaveformResult.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 FfiConverterDictionaryStringTypeWaveformResult.read(from: &buf)
        default: throw UniffiInternalError.unexpectedOptionalTag
        }
    }
}

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

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

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

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

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

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

#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 FfiConverterSequenceTypeBufferMetadata: FfiConverterRustBuffer {
    typealias SwiftType = [BufferMetadata]

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

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

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

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

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

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

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

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

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

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

    public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: WaveformResult] {
        let len: Int32 = try readInt(&buf)
        var dict = [String: WaveformResult]()
        dict.reserveCapacity(Int(len))
        for _ in 0..<len {
            let key = try FfiConverterString.read(from: &buf)
            let value = try FfiConverterTypeWaveformResult.read(from: &buf)
            dict[key] = value
        }
        return dict
    }
}
/**
 * Calculates the Region of Interest (ROI) based on a detected face rectangle.
 *
 * # Arguments
 * * `face` - The base bounding box of the detected face.
 * * `method` - The extraction method determining the offset values.
 * * `detector` - The type of face detector used.
 * * `container_width` - Optional maximum width boundary to clip the ROI.
 * * `container_height` - Optional maximum height boundary to clip the ROI.
 * * `force_even` - If true, ensures the resulting ROI has even width and height.
 *
 * # Returns
 * A `Rect` representing the calculated ROI.
 */
public func calculateRoi(face: Rect, method: RoiMethod, detector: FaceDetector, containerWidth: Float?, containerHeight: Float?, forceEven: Bool) -> Rect {
    return try!  FfiConverterTypeRect.lift(try! rustCall() {
    uniffi_vitallens_core_fn_func_calculate_roi(
        FfiConverterTypeRect.lower(face),
        FfiConverterTypeRoiMethod.lower(method),
        FfiConverterTypeFaceDetector.lower(detector),
        FfiConverterOptionFloat.lower(containerWidth),
        FfiConverterOptionFloat.lower(containerHeight),
        FfiConverterBool.lower(forceEven),$0
    )
})
}
public func computeBufferConfig(config: SessionConfig) -> BufferConfig {
    return try!  FfiConverterTypeBufferConfig.lift(try! rustCall() {
    uniffi_vitallens_core_fn_func_compute_buffer_config(
        FfiConverterTypeSessionConfig.lower(config),$0
    )
})
}
/**
 * Computes the Intersection over Union (IoU) of two rectangles.
 *
 * # Arguments
 * * `a` - First rectangle.
 * * `b` - Second rectangle.
 *
 * # Returns
 * The IoU ratio as a float between 0.0 and 1.0.
 */
public func computeIou(a: Rect, b: Rect) -> Float {
    return try!  FfiConverterFloat.lift(try! rustCall() {
    uniffi_vitallens_core_fn_func_compute_iou(
        FfiConverterTypeRect.lower(a),
        FfiConverterTypeRect.lower(b),$0
    )
})
}
public func getVitalInfo(vitalId: String) -> VitalDisplayMeta? {
    return try!  FfiConverterOptionTypeVitalDisplayMeta.lift(try! rustCall() {
    uniffi_vitallens_core_fn_func_get_vital_info(
        FfiConverterString.lower(vitalId),$0
    )
})
}
/**
 * Checks if an inner rectangle is sufficiently contained within an outer rectangle.
 *
 * # Arguments
 * * `inner` - The rectangle to check for containment.
 * * `outer` - The boundary rectangle.
 * * `min_overlap_pct` - The minimum required visible fraction of the inner rectangle.
 *
 * # Returns
 * `true` if the visible area meets or exceeds `min_overlap_pct`, otherwise `false`.
 */
public func isContained(inner: Rect, outer: Rect, minOverlapPct: Float) -> Bool {
    return try!  FfiConverterBool.lift(try! rustCall() {
    uniffi_vitallens_core_fn_func_is_contained(
        FfiConverterTypeRect.lower(inner),
        FfiConverterTypeRect.lower(outer),
        FfiConverterFloat.lower(minOverlapPct),$0
    )
})
}

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 var initializationResult: InitializationResult = {
    // Get the bindings contract version from our ComponentInterface
    let bindings_contract_version = 26
    // Get the scaffolding contract version by calling the into the dylib
    let scaffolding_contract_version = ffi_vitallens_core_uniffi_contract_version()
    if bindings_contract_version != scaffolding_contract_version {
        return InitializationResult.contractVersionMismatch
    }
    if (uniffi_vitallens_core_checksum_func_calculate_roi() != 39504) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_func_compute_buffer_config() != 60181) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_func_compute_iou() != 42017) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_func_get_vital_info() != 12718) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_func_is_contained() != 26927) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_method_bufferplanner_evaluate_target() != 53374) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_method_bufferplanner_is_ready() != 62024) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_method_bufferplanner_poll() != 59925) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_method_session_process() != 23803) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_method_session_reset() != 26380) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_constructor_bufferplanner_new() != 8442) {
        return InitializationResult.apiChecksumMismatch
    }
    if (uniffi_vitallens_core_checksum_constructor_session_new() != 38741) {
        return InitializationResult.apiChecksumMismatch
    }

    return InitializationResult.ok
}()

private func uniffiEnsureInitialized() {
    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