package pxds.lmmd.zmwf

import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import com.test.basd.supercleanermax.R
import org.json.JSONObject
import pxds.lmmd.zmwf.Khko.string

object Cisv {

    fun init() {
        val referrerClient = InstallReferrerClient.newBuilder(Lwfm.context).build()
        referrerClient.startConnection(object : InstallReferrerStateListener {
            override fun onInstallReferrerSetupFinished(responseCode: Int) {
                try {
                    when (responseCode) {
                        InstallReferrerClient.InstallReferrerResponse.OK -> {
                            val response = referrerClient.installReferrer
                            val installInfo = response.installReferrer
                            val obj = JSONObject()
                            obj.put(R.string.ހމޔބޅ_D.string(), response.installReferrer)
                            obj.put(R.string.ޘޏތޏނ_D.string(), response.referrerClickTimestampSeconds)
                            obj.put(R.string.ޠޑޔސމ_D.string(), response.installBeginTimestampSeconds)
                            obj.put(R.string.ޟޞޚޠޢ_D.string(), installInfo.toString())
                            Wspd.event(R.string.ދޝފމޡ_D.string(), ext = obj,isSingleEvent = true)
                        }

                        else -> {
                            Wspd.event(R.string.ހޅޗގޘ_D.string(), isSingleEvent = true)
                        }
                    }
                } catch (_: Exception) {
                    Wspd.event(R.string.ހޅޗގޘ_D.string(), isSingleEvent = true)
                }

            }

            override fun onInstallReferrerServiceDisconnected() {

            }
        })
    }
}