package com.base.appzxhy.business.ads

import com.base.appzxhy.MyApplication
import com.base.appzxhy.business.helper.EventUtils
import com.base.appzxhy.utils.LogEx
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
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 = ""
    var reqId = UUID.randomUUID().toString()
    var isUnLimit: Boolean = false


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

    fun adPulStart() {
        val obj = JSONObject()
        obj.put("ad_unit", adUnit)
        obj.put("from", from)
        obj.put("req_id", reqId)
        obj.put("ad_type", adUnit)
        EventUtils.event("ad_pull_start", ext = obj)
        LogEx.logDebug(TAG, "ad_pull_start_$adUnit $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_$adUnit $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_$adUnit $obj")
    }


}