package com.gh.gamecenter.entity

import com.gh.gamecenter.common.entity.LinkEntity
import com.google.gson.annotations.SerializedName

class StartupAdEntity(
    // 接口返回了个狗屎 code_id 过来，只能用 alternate 来 map 一下了
    @SerializedName(value = "_id", alternate = ["code_id"])
    var id: String,
    val desc: String,
    val button: Boolean,
    val jump: LinkEntity = LinkEntity(),
    val img: String = "",
    // 显示规则: none无, each每一次打开, everyday每一天一次, once一次
    val rule: String = "",
    val time: TimeEntity? = null,
    @SerializedName("type")
    private val _type: String? = null,
    @SerializedName("video")
    private val _video: VideoEntity? = null,
    @SerializedName("display_interval")
    private val _displayInterval: Int? = null
) {

    // 默认为图片
    val type: String
        get() = _type ?: AD_TYPE_IMG

    val isImageType: Boolean
        get() = type == AD_TYPE_IMG

    val video: VideoEntity
        get() = _video ?: VideoEntity()

    // 默认时长为 5s
    val displayInterval: Int
        get() = _displayInterval ?: 5

    class TimeEntity(val start: Long = 0, val end: Long = 0)

    companion object {
        private const val AD_TYPE_IMG = "img"
    }
}