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.home.custom.CustomPageTracker
import com.gh.gamecenter.home.custom.model.CustomCommonContentCollectionItem
import com.gh.gamecenter.home.custom.model.CustomPageItem
import com.gh.gamecenter.home.custom.model.CustomSplitCommonContentCollectionItem

class CommonContentCollectionTracker(private val pageLocation: PageLocation) {

    fun trackLinkContentCollectionClick(
        item: CustomPageItem,
        link: LinkEntity?,
        text: String,
        game: GameEntity? = null
    ) {
        val (linkContentCollectionId, linkContentCollectionName) = when {
            item is CustomCommonContentCollectionItem -> item.data.id to item.data.name
            item is CustomSplitCommonContentCollectionItem -> item.data.id to item.data.name
            else -> "" to ""
        }
        SensorsBridge.trackLinkContentCollectionClick(
            CustomPageTracker.LOCATION_CUSTOM_PAGE,
            "",
            "",
            linkContentCollectionName,
            linkContentCollectionId,
            item.position,
            link?.type ?: "",
            link?.link ?: "",
            link?.text ?: "",
            text,
            item.componentStyle,
            pageLocation.bottomTab,
            pageLocation.severalTabPageId,
            pageLocation.severalTabPageName,
            pageLocation.tabPosition,
            pageLocation.tabContent,
            pageLocation.pageId,
            pageLocation.pageName,
            game?.id ?: "",
            game?.name ?: ""
        )
    }
}