package com.convenient.android.lib.ui.sample.ad.viewmodel

import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import com.composition.android.ad.admob.load.AdmobAdLoader
import com.composition.android.ad.applovinmax.load.AppLovinMaxLoader
import com.composition.android.ad.csj.load.CSJAdLoader
import com.composition.android.ad.gromore.load.GroMoreAdLoader
import com.composition.android.lib.ad.AdManager
import com.composition.android.lib.ad.basic.Advertisers
import com.composition.android.lib.ad.impl.UnknownAdLoader
import com.composition.android.lib.ad.interfaces.AdLoader

/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/9/5
 * description:
 */
class AdConfigViewModel : ViewModel() {

    var advertisers = mutableStateOf(Advertisers.UNKNOWN)

    fun changeRegisterAdvertisers(advertisers: Advertisers) {
        if (this.advertisers.value == advertisers) {
            this.advertisers.value = Advertisers.UNKNOWN
        } else {
            this.advertisers.value = advertisers
        }
        AdManager.instance.registerAdLoader(getAdLoader(advertisers = this.advertisers.value))
    }

    fun getAdLoader(advertisers: Advertisers):  AdLoader {
        return when (advertisers) {
            Advertisers.Admob ->  AdmobAdLoader()
            Advertisers.CSJ ->  CSJAdLoader()
            Advertisers.GroMore ->  GroMoreAdLoader()
            Advertisers.AppLovinMax -> AppLovinMaxLoader()
            else -> UnknownAdLoader()
        }
    }


}