package com.base.locationsharewhite.ads

import com.base.locationsharewhite.utils.AppPreferences
import org.json.JSONObject

/**
 * 广告限制配置
 *
 * @property isInBlackList 是否在黑名单
 * @property numDisplayLimit  展示次数限制 -1为不限制，0为彻底关闭显示
 * @property numRequestLimit  请求次数限制 -1为不限制，0为彻底关闭显示
 * @property numClickLimit  点击次数限制 -1为不限制，0为彻底关闭显示
 * @property timeInterval  广告间隔时间
 */
data class AdsConfigBean(
    var isInBlackList: Boolean = false,
    var numDisplayLimit: Int = -1,
    var numRequestLimit: Int = -1,
    var numClickLimit: Int = -1,
    var timeInterval: Int = 1,
    var openAdLoading: Int = 15,
) {
    companion object {
        fun getSpConfigBean(): AdsConfigBean {
            val adsConfigBean = AdsConfigBean()
            adsConfigBean.apply {
                isInBlackList = AppPreferences.getInstance().getBoolean("isInBlackList", false)
                numDisplayLimit = AppPreferences.getInstance().getString("numDisplayLimit", "-1").toInt()
                numRequestLimit = AppPreferences.getInstance().getString("numRequestLimit", "-1").toInt()
                numClickLimit = AppPreferences.getInstance().getString("numClickLimit", "-1").toInt()
                timeInterval = AppPreferences.getInstance().getString("timeInterval", "1").toInt()
                openAdLoading = AppPreferences.getInstance().getString("openAdLoading", "15").toInt()
            }
            return adsConfigBean
        }

        fun createDefaultAdJson(): JSONObject {
            val json = JSONObject()
            json.put("numDisplayLimit", "-1")
            json.put("numRequestLimit", "-1")
            json.put("numClickLimit", "-1")
            json.put("timeInterval", "1")
            json.put("openAdLoading", "15")
            return json
        }
    }
}