package com.base.scanqrclear.bean

data class WhatsappUIBean(val phone: String) : ScanBean(FunctionUIBean.KEY_WHATSAPP) {

    companion object {

        fun createWhatsappUIBean(qrCodeValue: String): WhatsappUIBean {
            val split = qrCodeValue.split("=")
            val phone = if (split.size == 2) split[1] else ""
            return WhatsappUIBean(phone)
        }

        //        whatsapp://send?phone=+861768923756
        fun WhatsappUIBean.createWhatsappQrString(): String {
            val qrContent = StringBuilder()
            qrContent.append("whatsapp://send?")
                .append("phone=").append(this.phone)
            return qrContent.toString()
        }

        fun isWhatsappQR(qrCodeValue: String): Boolean {
            return qrCodeValue.startsWith("whatsapp://")
        }
    }
}