package com.gh.gamecenter.entity

import com.gh.common.util.PackageUtils
import com.gh.gamecenter.common.entity.IconFloat
import com.gh.gamecenter.feature.entity.GameEntity
import com.google.gson.annotations.SerializedName
import com.halo.assistant.HaloApp

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 isSmoothGame: Boolean = false, // 是否是畅玩游戏
    var tag: Any? = null
) {

    companion object {
        fun transformGameInstall(game: GameEntity, installedPkgName: String): GameInstall {
            val gameInstall = GameInstall()
            val application = HaloApp.getInstance().application
            gameInstall.isSignByGh = PackageUtils.isSignedByGh(application, installedPkgName)
            gameInstall.installTime = PackageUtils.getInstalledTime(application, installedPkgName)
            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.isSmoothGame = game.isVGame()
            return gameInstall
        }
    }
}