package com.gh.gamecenter.core.utils

import com.lightgame.utils.AppManager

/**
 * 用来简单获取上一个跳转页面的跳转信息的辅助类
 * 简单解藕，不想层层传递数据可以把简单数据放这里面
 * 暂只支持单页面(上一 activity)记录，不支持连续跨页
 */
object PageSwitchDataHelper {

    const val PAGE_BUSINESS_NAME = "page_business_name" // 页面业务名字
    const val PAGE_BUSINESS_TYPE = "page_business_type" // 页面业务类型
    const val PAGE_BUSINESS_ID = "page_business_id" // 页面业务 id

    const val PAGE_GAME_DETAIL_RECOMMEND = "page_game_detail_recommend"

    private var mDataFromTheLastPage: Pair<String, HashMap<String, String>>? = null

    @JvmStatic
    fun popLastPageData(): HashMap<String, String>? {
        AppManager.getInstance().previousActivity()?.let {
            if (System.identityHashCode(it).toString() == mDataFromTheLastPage?.first
                && mDataFromTheLastPage?.second != null
            ) {
                return mDataFromTheLastPage!!.second.also { mDataFromTheLastPage = null }
            }
        }
        return null
    }

    @JvmStatic
    fun pushCurrentPageData(data: HashMap<String, String>) {
        AppManager.getInstance().currentActivity()?.let {
            mDataFromTheLastPage = Pair(System.identityHashCode(it).toString(), data)
        }
    }

}