package com.gh.gamecenter.entity

import com.gh.common.exposure.ExposureEvent
import com.google.gson.annotations.SerializedName

data class GameUpdateEntity(
    @SerializedName("game_id")
    var id: String = "",
    var name: String? = null,
    var icon: String? = null,
    @SerializedName("ori_icon")
    var rawIcon: String? = null,
    @SerializedName("icon_subscript")
    var iconSubscript: String? = "",
    @SerializedName("package")
    var packageName: String = "",
    var size: String? = null,
    var version: String? = null,
    var currentVersion: String? = null,
    @SerializedName("gh_version")
    var ghVersion: String? = null,
    var url: String? = null,
    var platform: String? = null,
    var readablePlatform: String? = "",
    var isPluggable: Boolean = false,
    var isPluggableDownloaded: Boolean = false, // 插件化是否被下载完成
    var etag: String? = null,
    var brief: String? = null,
    var tag: ArrayList<String>? = null,
    var tagStyle: ArrayList<TagStyleEntity> = ArrayList(),
    // 控制是否显示插件化 默认：open，取值有：open/only_index/only_game/close
    var plugin: String? = "",
    // 只控制首页是否显示插件化 open/close(此开关优先级最高)
    @SerializedName("index_plugin")
    var indexPlugin: String = "open",
    var exposureEvent: ExposureEvent? = null,
    var download: Int = 0/*7天下载量*/,
    @SerializedName("p_button_add_word")
    var pluginDesc: String = "", //插件功能描述
    var pluggableCollection: GameCollectionEntity? = null, // 插件化包所在的合集
    var format: String = "",
    var signature: String? = "",
    var category: String? = "",
    var md5: String? = "",
    var downloadStatus: String? = ""
) {

    fun isShowPlugin(location: PluginLocation): Boolean {
        if (plugin.isNullOrEmpty() || "open" == plugin || plugin == location.name) {
            return true
        }
        return false
    }

    fun transformGameEntity(): GameEntity {
        val gameEntity = GameEntity()
        gameEntity.id = id
        gameEntity.name = name
        gameEntity.icon = icon
        gameEntity.rawIcon = rawIcon
        gameEntity.iconSubscript = iconSubscript
        gameEntity.tagStyle = tagStyle
        gameEntity.brief = brief
        gameEntity.download = download
        gameEntity.isPluggable = true
        gameEntity.indexPlugin = indexPlugin
        gameEntity.pluginDesc = pluginDesc
        gameEntity.pluggableCollection = pluggableCollection
        gameEntity.category = category

        val apkEntity = ApkEntity()
        apkEntity.url = url
        apkEntity.packageName = packageName
        apkEntity.size = size
        apkEntity.version = version
        apkEntity.ghVersion = ghVersion
        apkEntity.setPlatform(platform!!)
        apkEntity.etag = etag
        apkEntity.plugin = plugin
        apkEntity.format = format
        apkEntity.signature = signature

        val apk = ArrayList<ApkEntity>()
        apk.add(apkEntity)
        gameEntity.setApk(apk)
        return gameEntity
    }
}

enum class PluginLocation {
    only_index, // 首页插件化区域/下载管理
    only_game, // 游戏页面
    force_open, // 无视后台判断强制打开
    force_close, // 无视后台判断强制关闭
}


