package com.composition.android.lib.ad.bean

import com.composition.android.lib.ad.basic.AdType
import com.composition.android.lib.ad.basic.Advertisers
import com.composition.android.lib.ad.impl.NormalStrategy
import com.composition.android.lib.ad.basic.strategy.IStrategy
import com.composition.android.lib.ad.interfaces.IAdSize


/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/9/1
 * description:广告单元信息
 * 一个广告位，包含使用的广告位名称，广告商、广告类型、广告ID、加载配置、展示配置
 */
open class AdUnitBean(
    var adSlotName : String,
    var advertisersName: String,
    var adType: String,
    var adUnitId: String,
    var adSize : IAdSize<*>?  = null,
    var loadStrategy : IStrategy = NormalStrategy(),
    var requestAdConfig: AdUnitLoadConfig = AdUnitLoadConfig()
) {

    companion object{
        fun emptyAdUnitBean() : AdUnitBean = AdUnitBean(adSlotName = "", advertisersName = "", adType = "", adUnitId = "")
    }

    /**
     * 获取广告商枚举类型
     */
    fun getAdvertisers(): Advertisers {
        return try {
            Advertisers.valueOf(advertisersName)
        } catch (e: Exception) {
            Advertisers.UNKNOWN
        }
    }

    override fun toString(): String {
        return "广告位:${adSlotName}\n广告商:${advertisersName}\n广告类型:${adType}\n广告id:${adUnitId}"
    }

    override fun equals(other: Any?): Boolean {
        return when(other){
            !is AdUnitBean-> false
            else-> this === other || this.adSlotName.equals(other.adSlotName) && this.advertisersName.equals(other.advertisersName) && this.adType.equals(other.adType) && this.adUnitId.equals(other.adUnitId)
        }
    }

    fun getAdType() : AdType{
        return try {
            AdType.valueOf(adType)
        }catch (e : Exception){
            AdType.UNKNOWN
        }
    }

    fun isAvailable() : Boolean{
        return adUnitId.isNotEmpty() && advertisersName.isNotEmpty() && adType.isNotEmpty() && adSlotName.isNotEmpty()
    }

}


