package com.tgv.malware.business.ads

import com.tgv.malware.GlobalConfig
import com.google.android.gms.ads.appopen.AppOpenAd
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.nativead.NativeAd
import com.google.android.gms.ads.rewarded.RewardedAd
import com.reyun.solar.engine.SolarEngineManager
import com.reyun.solar.engine.infos.SEAdImpEventModel
import org.json.JSONObject

/**
 * https://help.solar-engine.com/cn/docs/yu-ding-yi-shi-jian
 */
object SolarEngineEvent {

    fun eventSolar(ad: Any?, valueMicros: Long) {

        val json = JSONObject()
        //变现平台
        val adNetworkPlatform = "AdMob"
        //聚合平台标识
        val mediationPlatform = "admob"
        //广告的类型
//        adType 为激励视频时，只需要传入 1
//        1：激励视频
//        2：开屏
//        3：插屏
//        4：全屏视频
//        5：Banner
//        6：信息流
//        7：短视频信息流
//        8：大横幅
//        9：视频贴片
//        10：中等尺寸横幅
//        0：其它
        var adType = -1
        //变现平台的应用 ID
        val adNetworkAppID = GlobalConfig.ID_ADMOB_APPLICATION
        //变现平台的变现广告位 ID
        var adNetworkADID = ""
        //广告 ecpm，单位：元（广告千次展现的变现收入，0或负值表示没传，单位为元）
        val ecpm = valueMicros / 1000.0
        //货币种类
        val currencyType = "USD"

        when (ad) {
            is AppOpenAd -> {
                adType = 2
                adNetworkADID = ad.adUnitId
            }

            is InterstitialAd -> {
                adType = 3
                adNetworkADID = ad.adUnitId
            }

            is NativeAd -> {
                adType = 6
                adNetworkADID = GlobalConfig.ID_ADMOB_NATIVE
            }

            is RewardedAd -> {
                adType = 1
                adNetworkADID = ad.adUnitId
            }

            else -> {//banner
                adType = 5
                adNetworkADID = GlobalConfig.ID_ADMOB_BANNER
            }
        }

        try {
            val seAdImpEventModel = SEAdImpEventModel(
                adNetworkPlatform,
                mediationPlatform,
                adType,
                adNetworkAppID,
                adNetworkADID,
                ecpm,
                currencyType,
                true,
                json
            )
            SolarEngineManager.getInstance().trackAdImpression(seAdImpEventModel)
        } catch (e: Exception) {
            //
        }

    }
}