
package com.cloud.hmg_patient_app.whatsapp

import android.content.Context
import android.content.Intent
import com.whatsapp.otp.android.sdk.WhatsAppOtpHandler
import com.whatsapp.otp.android.sdk.WhatsAppOtpIncomingIntentHandler
import java.lang.ref.WeakReference

object WhatsApp {
    val whatsAppOtpHandler = WhatsAppOtpHandler()
    inline fun  handleOTP ( intent: Intent, crossinline validateOTP:(code: String )-> Unit) =
        WhatsAppOtpIncomingIntentHandler().processOtpCode(
            intent,
            // call your function to validate
            {code -> validateOTP(code) },
            {error,exception->
                println("the error is ${error.name}")
                println("the exception stacktrace is ${exception.message}")
                println("the exception is cause ${exception.cause}")
            })


    fun performHandShake(context : WeakReference<Context>)  = whatsAppOtpHandler.sendOtpIntentToWhatsApp(context.get()!!)



    fun isWhatsAppInstalled(context : WeakReference<Context>) : Boolean  = whatsAppOtpHandler.isWhatsAppInstalled(context.get()!!)


}
