package com.base.scanqrclear.ads

import com.base.scanqrclear.MyApplication
import com.base.scanqrclear.helper.EventUtils
import com.base.scanqrclear.utils.LogEx
import org.json.JSONObject
import java.util.UUID


val taichiPref by lazy {
    MyApplication.appContext.getSharedPreferences("TaichiTroasCache", 0)
}

val taichiSharedPreferencesEditor by lazy {
    taichiPref.edit()
}


abstract class AdEvent {

    abstract val TAG: String

    var adUnit: String = ""
    var from: String = ""
    val reqId = UUID.randomUUID().toString()

    fun adPrepareShow() {
        val obj1 = JSONObject()
        obj1.put("ad_unit", adUnit)
        obj1.put("req_id", reqId)
        obj1.put("from", from)
        EventUtils.event("ad_prepare_show", ext = obj1)
        LogEx.logDebug(TAG, "ad_prepare_show $obj1")
    }

    fun adPulStart() {
        val obj = JSONObject()
        obj.put("req_id", reqId)
        obj.put("ad_unit", adUnit)
        obj.put("ad_type", adUnit)
        obj.put("from", from)
        EventUtils.event("ad_pull_start", ext = obj)
        LogEx.logDebug(TAG, "ad_pull_start $obj")
    }

    fun adShowError(reason: Any) {
        val obj = JSONObject()
        obj.put("ad_unit", adUnit)
        obj.put("req_id", reqId)
        obj.put("from", from)
        obj.put("reason", reason.toString())
        EventUtils.event("ad_show_error", ext = obj)
        LogEx.logDebug(TAG, "ad_show_error $obj")
    }

    fun adLimited(value: String) {
        val obj = JSONObject()
        obj.put("ad_unit", adUnit)
        obj.put("req_id", reqId)
        obj.put("from", from)
        EventUtils.event("ad_limit", value, obj)
        LogEx.logDebug(TAG, "ad_limit $value $obj")
    }


}