package com.composition.android.lib.ad

import android.content.Context
import com.composition.android.lib.ad.basic.Advertisers
import com.composition.android.lib.ad.bean.OnAdShow
import com.composition.android.lib.ad.impl.NormalAdListener
import com.composition.android.lib.ad.interfaces.AdListener
import com.composition.android.lib.ad.interfaces.AdLoader
import com.composition.android.lib.ad.interfaces.Initialize

/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/9/1
 * description:广告管理类
 */
class AdManager {


    companion object {
        val instance by lazy {
            AdManager()
        }

        const val TAG = "广告组件"
    }

    /**
     * 上下文，使用application
     */
    lateinit var context: Context

    /**
     * 是否开启日志
     */
    var logEnable = false

    /**
     * 广告全局开关
     */
    var enableAd: Boolean = true

    internal var adLoaderLists = mutableListOf<Pair<Advertisers, AdLoader>>()

    var globalListener: OnAdShow? = null

    /**
     * 广告初始化
     */
    fun init(applicationContext: Context, logEnable: Boolean = false) {
        this.context = applicationContext
        this.logEnable = logEnable
    }

    /**
     * 注册广告加载器
     */
    fun registerAdLoader(vararg adLoader: Pair<Advertisers, AdLoader>) {
        adLoaderLists.clear()
        adLoaderLists.addAll(adLoader)
    }


    fun addGlobalAdShowListener(adListener: OnAdShow) {
        globalListener = adListener
    }


    /**
     * 初始化广告商SDK
     */
    fun initAdvertisersSDK(context: Context, vararg advertisersSdk: Initialize) {
        for (initialize in advertisersSdk) {
            initialize.init(context)
        }
    }

}