package com.gh.gamecenter.entity

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

/**
 * Created by khy on 2016/12/13.
 */
@Parcelize
data class LibaoEntity(
    @SerializedName(value = "_id", alternate = arrayOf("libao_id"))
    var id: String? = null,
    var content: String? = null,
    var game: SimpleGame? = null,
    private var icon: String? = null,
    var name: String? = null,
    var des: String? = null, //使用说明
    var platform: String? = null,
    @SerializedName("type", alternate = ["status"])
    var status: String? = null,
    var beforeStatus: String? = null,
    var code: String? = null,
    var available: Int = 0,
    var total: Int = 0,
    @SerializedName("package")
    var packageName: String? = null,
    @SerializedName("active")
    var isActive: Boolean = false, // 存号箱数据是否被删除(true:没被删除(可以作为存号箱列表标识), false:删除(不会显示在列表))
    var time: Long = 0,
    var repeat: Int = 0, // 剩余可领取数量
    @SerializedName("me")
    var me: MeEntity? = null,
    var universal: Boolean = false,//是否是通用码，true/false
    var expires: Int = 0,//过期时间
    @SerializedName("libao_active")
    var libaoActive: Boolean = false,//后台礼包是否被隐藏
    @SerializedName("receive_limit")
    var receiveLimit: String = "", //领取限制，暂时只有"通过活动自动发放"->“activity_grant”
    @SerializedName("activity_link")
    var activityLink: ActivityLink = ActivityLink(), //关联活动链接数据
    @SerializedName("app_and_plugin_hide")
    var appAndPluginHide: Boolean = false, //app和插件内不显示

    //本地字段
    var clickReceiveBtnIn: Boolean = false//是否是点击列表领取按钮进入
) : Parcelable {

    @Parcelize
    data class ActivityLink(
        var link: String = "",
        var text: String = "",
        var url: String = ""
    ) : Parcelable

    fun getIcon(): String {
        return if (game != null) {
            game!!.getIcon()
        } else {
            icon ?: ""
        }
    }

    fun getIconSubscript(): String? {
        return if (game != null) {
            game!!.iconSubscript
        } else {
            null
        }
    }

    // 不改变原有的内存地址 用于更新外部列表页面
    fun resetLibaoEntity(entity: LibaoEntity) {
        this.id = entity.id
        this.content = entity.content
        this.game = entity.game
        this.name = entity.name
        this.des = entity.des
        this.platform = entity.platform
        this.status = entity.status
        this.beforeStatus = entity.status
        this.code = entity.code
        this.available = entity.available
        this.total = entity.total
        this.packageName = entity.packageName
        this.isActive = entity.isActive
        this.time = entity.time
        this.repeat = entity.repeat
        this.me = entity.me
    }

    companion object {

        const val TAG: String = "LibaoEntity"

        fun createLibaoEntity(concernEntity: ConcernEntity, libaoStatusEntity: LibaoStatusEntity): LibaoEntity {
            val libaoEntity = LibaoEntity()
            libaoEntity.id = concernEntity.id
            libaoEntity.content = concernEntity.content
            libaoEntity.game = concernEntity.game
            libaoEntity.icon = concernEntity.gameIcon
            libaoEntity.name = concernEntity.name
            libaoEntity.platform = concernEntity.platform
            libaoEntity.status = libaoStatusEntity.status
            libaoEntity.code = libaoStatusEntity.code
            libaoEntity.available = libaoStatusEntity.available
            libaoEntity.total = libaoStatusEntity.total
            libaoEntity.me = concernEntity.me
            libaoEntity.beforeStatus = libaoStatusEntity.beforeStatus
            return libaoEntity
        }
    }
}
