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

import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
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
import com.composition.android.ad.admob.load.AdmobAdLoader
import com.composition.android.ad.csj.load.CSJAdLoader
import com.composition.android.ad.gromore.load.GroMoreAdLoader

/**
 * @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(this.advertisers.value))
    }

    fun getAdLoader(advertisers: Advertisers): Pair<Advertisers, AdLoader> {
        return when (advertisers) {
            Advertisers.Admob -> Advertisers.Admob to AdmobAdLoader()
            Advertisers.CSJ -> Advertisers.CSJ to CSJAdLoader()
            Advertisers.GroMore -> Advertisers.GroMore to GroMoreAdLoader()
            else -> Advertisers.UNKNOWN to UnknownAdLoader()
        }
    }


}