package com.gh.gamecenter.home.custom.tracker

import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.utils.SensorsBridge
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.feature.entity.PageLocation
import com.gh.gamecenter.feature.minigame.MiniGameItemHelper
import com.gh.gamecenter.home.custom.CustomPageTracker
import com.gh.gamecenter.home.custom.model.*

class GameSubjectCollectionTracker(private val pageLocation: PageLocation) {

    fun trackGameListCollectionClickWithUser(item: CustomSubjectCollectionItem, userId: String) {
        val otherParams = hashMapOf<String, Any>(
            SensorsBridge.KEY_MONGOLD_ID to userId
        )
        trackGameListCollectionClick(item, "个人主页", otherParams)
    }

    fun trackGameListCollectionClickWithGameCollection(
        item: CustomSubjectCollectionItem,
        gameCollectId: String,
        gameCollectTitle: String

    ) {
        val otherParams = hashMapOf<String, Any>(
            SensorsBridge.KEY_GAME_COLLECT_ID to gameCollectId,
            SensorsBridge.KEY_GAME_COLLECT_TITLE to gameCollectTitle
        )
        trackGameListCollectionClick(item, "游戏单", otherParams)
    }

    fun trackGameListCollectionClickWithGame(item: CustomSubjectCollectionItem, gameId: String, gameName: String?) {
        val otherParams = hashMapOf<String, Any>(
            SensorsBridge.KEY_GAME_ID to gameId,
            SensorsBridge.KEY_GAME_NAME to (gameName ?: "")
        )
        trackGameListCollectionClick(item, "游戏", otherParams)
    }

    fun trackGameListCollectionClick(
        item: CustomSubjectCollectionItem,
        text: String,
        otherParams: HashMap<String, Any> = hashMapOf()
    ) {
        SensorsBridge.trackGameListCollectionClick(
            CustomPageTracker.LOCATION_CUSTOM_PAGE,
            item.data.id,
            item.data.name,
            text,
            pageLocation.bottomTab,
            pageLocation.severalTabPageId,
            pageLocation.severalTabPageName,
            pageLocation.tabPosition,
            pageLocation.tabContent,
            pageLocation.pageId,
            pageLocation.pageName,
            item.componentStyle,
            otherParams
        )
    }


    fun trackColumnCollectionClick(
        item: CustomSubjectCollectionItem,
        subject: CustomPageData.LinkColumnCollection.CustomSubjectEntity?,
        game: GameEntity?,
        text: String,
        link: LinkEntity? = null
    ) {
        SensorsBridge.trackColumnCollectionClick(
            CustomPageTracker.LOCATION_CUSTOM_PAGE,
            "",
            "",
            item.data.name,
            item.data.id,
            item.position,
            subject?.title ?: "",
            subject?.id ?: "",
            text,
            item.componentStyle,
            pageLocation.bottomTab,
            pageLocation.severalTabPageId,
            pageLocation.severalTabPageName,
            pageLocation.tabPosition,
            pageLocation.tabContent,
            pageLocation.pageId,
            pageLocation.pageName,
            game?.id ?: "",
            game?.name ?: "",
            link?.type ?: "",
            link?.link ?: "",
            link?.text ?: "",
            adGroupId = game?.adGroupId ?: ""
        )
    }

    fun trackGameListCollectionClickWithMore(item: CustomSubjectCollectionItem, link: LinkEntity) {
        val otherParams = HashMap<String, Any>().apply {
            put(SensorsBridge.KEY_LINK_ID, link.link ?: "")
            put(SensorsBridge.KEY_LINK_TYPE, link.type ?: "")
            put(SensorsBridge.KEY_LINK_TEXT, link.text ?: "")
        }
        trackGameListCollectionClick(item, "更多", otherParams)
    }

    fun trackMiniGameClick(
        item: CustomSubjectCollectionItem,
        subject: CustomPageData.LinkColumnCollection.CustomSubjectEntity?,
        game: GameEntity
    ) {
        MiniGameItemHelper.trackMiniGameClick(
            gameEntity = game,
            pageLocation.bottomTab,
            pageLocation.severalTabPageId,
            pageLocation.severalTabPageName,
            pageLocation.tabPosition,
            pageLocation.tabContent,
            pageLocation.pageId,
            pageLocation.pageName,
            subject?.id ?: "",
            subject?.title ?: "",
            "自定义页面",
            item.componentStyle,
            "",
        )
    }
}