package com.composition.android.ad.gromore.impl

import android.content.Context
import com.bytedance.sdk.openadsdk.TTAdConfig
import com.bytedance.sdk.openadsdk.TTAdSdk
import com.bytedance.sdk.openadsdk.TTCustomController
import com.bytedance.sdk.openadsdk.mediation.init.MediationConfig
import com.bytedance.sdk.openadsdk.mediation.init.MediationConfigUserInfoForSegment
import com.composition.android.lib.ad.AdManager
import com.composition.android.lib.ad.interfaces.Initialize
import com.composition.android.lib.ad.util.adLogE

/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/9/15
 * description:GroMore SDK初始化
 */
class GroMoreInitialize(var appId: String) : Initialize {

    override fun init(context: Context) {
        val userInfo = MediationConfigUserInfoForSegment()
        userInfo.userId = "msdk-demo"
        userInfo.gender = MediationConfigUserInfoForSegment.GENDER_MALE
        userInfo.channel = "msdk-channel"
        userInfo.subChannel = "msdk-sub-channel"
        userInfo.age = 999
        userInfo.userValueGroup = "msdk-demo-user-value-group"

        val customInfos: MutableMap<String, String> = HashMap()
        customInfos["aaaa"] = "test111"
        customInfos["bbbb"] = "test222"
        userInfo.customInfos = customInfos

        TTAdSdk.init(context, TTAdConfig.Builder()
            .appId(appId)
            .useTextureView(true)
            .appName(context.packageName)
            .supportMultiProcess(true)
            .debug(AdManager.instance.isDebug)
            .useMediation(true)
            .customController(object : TTCustomController() {

            })
            .setMediationConfig(MediationConfig.Builder().setMediationConfigUserInfoForSegment(userInfo).build())
            .build(), object : TTAdSdk.InitCallback {
            override fun success() {
                TTAdSdk.isInitSuccess()
                adLogE(AdManager.TAG, "GroMoreSDK初始化完成 ---- 版本号:${TTAdSdk.getAdManager().sdkVersion}")
            }

            override fun fail(p0: Int, p1: String?) {
                adLogE(AdManager.TAG, "GroMoreSDK初始化失败")
            }
        })
    }
}