package com.gh.gamecenter.feature.entity

import com.therouter.TheRouter
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.entity.IconFloat
import com.gh.gamecenter.core.provider.IPackageUtilsProvider
import com.gh.gamecenter.feature.HaloApp
import com.google.gson.annotations.SerializedName

data class GameInstall(
    @SerializedName("_id")
    var id: String? = "",
    var packageName: String = "",
    var name: String? = "",
    var icon: String? = "",
    var iconSubScript: String? = "",
    var iconFloat: IconFloat? = null,
    var isSignByGh: Boolean = false,
    var installTime: Long = 0,
    var version: String = "",
    var isVGame: Boolean = false, // 是否是畅玩游戏
    var downloadStatus: String? = "", // 下载状态，对应 GameEntity 的 downloadStatus
    var category: String? = "", // 类型，对应 GameEntity 的 category
    var tag: Any? = null
) {

    companion object {
        fun transformGameInstall(game: GameEntity,
                                 installedPkgName: String,
                                 isVGame: Boolean = false
        ): GameInstall {
            val gameInstall = GameInstall()
            val application = HaloApp.getInstance()
            val packageUtils = TheRouter.get(IPackageUtilsProvider::class.java)
            gameInstall.isSignByGh = packageUtils?.isSignedByGh(application, installedPkgName) == true
            gameInstall.installTime = packageUtils?.getInstalledTime(application, installedPkgName) ?: 0
            gameInstall.id = game.id
            gameInstall.name = game.name
            gameInstall.icon = game.rawIcon ?: game.icon
            gameInstall.iconSubScript = game.iconSubscript
            gameInstall.iconFloat = game.iconFloat
            gameInstall.version = packageUtils?.getVersionNameByPackageName(installedPkgName) ?: "unknown"
            gameInstall.packageName = installedPkgName
            gameInstall.isVGame = isVGame
            gameInstall.downloadStatus = game.downloadStatus
            gameInstall.category = game.category
            return gameInstall
        }
    }
}