package com.base.scanqrclear.bean

import com.base.scanqrclear.bean.FunctionUIBean.Companion.KEY_ADDRESS

data class AddressUIBean(
    val longitude: String,
    val latitude: String,
) : ScanBean(KEY_ADDRESS) {

    //    毛主席像：30.65889627699442, 104.0657291232703 google地图格式 latitude, longitude
    //    geo:104.065,30.658
    companion object {

        fun isAddressQR(qrCodeValue: String): Boolean {
            return qrCodeValue.startsWith("geo:")
        }

        fun createAddressUIBean(qrCodeValue: String): AddressUIBean {
            var longitude = ""
            var latitude = ""

            kotlin.runCatching {
                val sub = qrCodeValue.subSequence("geo:".length, qrCodeValue.length)
                val split = sub.split(",")
                longitude = split[0]
                latitude = split[1]
            }

            return AddressUIBean(longitude, latitude)
        }

        fun AddressUIBean.createAddressUIBeanQrString(): String {
            return "geo:$longitude,$latitude"
        }
    }
}
