package com.base.datarecovery.ads.max

import android.app.Activity
import com.applovin.mediation.MaxAd
import com.base.datarecovery.utils.EventUtils
import org.json.JSONObject

object AdMaxEvent {
    fun clickAd(nativeAd: MaxAd, adUnit: String) {

//        val response = responseInfo?.adapterResponses?.getOrNull(0)
        val obj = JSONObject()
//        obj.put("source", response?.adSourceName)
        obj.put("source", nativeAd.dspName)
        obj.put("ad_unit", adUnit)

//        val credentials = mapOf(
//            "placementid" to response?.credentials?.get("placementid"),
//            "appid" to response?.credentials?.get("appid"),
//            "pubid" to response?.credentials?.get("pubid")
//        )
//        obj.put("credentials", credentials.toString())
//        obj.put("session_id", responseInfo?.responseId)
//        obj.put("networkname", responseInfo?.mediationAdapterClassName)
        obj.put("networkname", nativeAd.networkName)
        if (adUnit != "nativeAd") {
            EventUtils.event("ad_click", ext = obj)
        } else {
            EventUtils.event("bigimage_ad_click", ext = obj)
        }
    }

    fun showAd(nativeAd: MaxAd, adUnit: String, activity: Activity? = null) {
//        val response = responseInfo?.adapterResponses?.getOrNull(0)
        val obj = JSONObject()
//        obj.put("source", response?.adSourceName)
        obj.put("ad_unit", adUnit)
        obj.put("networkname", nativeAd.networkName)
//        val credentials = mapOf(
//            "placementid" to response?.credentials?.get("placementid"),
//            "appid" to response?.credentials?.get("appid"),
//            "pubid" to response?.credentials?.get("pubid")
//        )
//        obj.put("credentials", credentials.toString())
//        obj.put("session_id", responseInfo?.responseId)
        obj.put("from", activity?.javaClass?.simpleName)
        if (adUnit != "nativeAd") {
            EventUtils.event("ad_show", ext = obj)
        } else {
            EventUtils.event("bigimage_ad_show", ext = obj)
        }
    }
}