package com.gh.gamecenter.home.custom

import com.gh.download.DownloadManager
import com.gh.gamecenter.feature.entity.GameEntity

class GamePositionAndPackageHelper {

    private val _positionAndPackageMap = HashMap<String, Int>()
    val positionAndPackageMap: HashMap<String, Int> = _positionAndPackageMap

    fun putGamePositionAndPackage(game: GameEntity, position: Int) {
        var packages = ""
        for (apkEntity in game.getApk()) {
            packages += apkEntity.packageName
        }
        _positionAndPackageMap[packages + position] = position
        game.gameLocation = GameEntity.GameLocation.INDEX
        game.setEntryMap(DownloadManager.getInstance().getEntryMap(game.name))
    }

    fun putAll(hashMap: HashMap<String, Int>) {
        _positionAndPackageMap.putAll(hashMap)
    }

    fun clear() {
        _positionAndPackageMap.clear()
    }

    companion object {

        fun HashMap<String, Int>.putGameWithPosition(game: GameEntity, position: Int) {
            var packages = ""
            game.getApk().forEach {
                packages += it.packageName
            }
            put(packages + position, position)
            game.gameLocation = GameEntity.GameLocation.INDEX
        }
    }
}