package com.gh.gamecenter.home.custom.eventlistener

import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.entity.RatingComment
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.home.custom.CustomPageViewModel
import com.gh.gamecenter.home.custom.model.CustomPageData
import com.gh.gamecenter.home.custom.model.CustomSubjectCollectionItem
import com.gh.gamecenter.home.custom.tracker.OtherItemTracker
import com.lightgame.download.DownloadEntity

class OtherItemEventHelper(
    viewModel: CustomPageViewModel
) : CustomPageItemChildEventHelper(viewModel) {

    private val tracker = OtherItemTracker(viewModel.pageLocation)

    fun navigateToGameDetailPageByGame(childPosition: Int, game: GameEntity) {
        viewModel.navigateToGameDetailPageByGame(_item, childPosition, game)
    }

    fun onDownloadButtonClick(childPosition: Int, game: GameEntity) {
        viewModel.onDownloadButtonClick(_item, childPosition, game)
    }

    fun navigateSubjectCollectionPage(
        childPosition: Int,
        subjectEntity: CustomPageData.LinkColumnCollection.CustomSubjectEntity,
    ) {
        val item = _item
        if (item is CustomSubjectCollectionItem) {
            if (item.isSubjectCollection) {
                viewModel.navigateSubjectCollectionPage(item, childPosition, subjectEntity)
            } else {
                viewModel.navigateGameListDetailPage(item, childPosition, subjectEntity)
            }

        }
    }

    fun onUserClick(userId: String) {
        viewModel.navigateUserHomePage(_item, userId)
    }

    fun navigateToAmway() {
        viewModel.navigateToAmway(_item)
    }

    fun navigateToBadgeWall(comment: RatingComment) {
        viewModel.navigateToBadgeWall(_item, comment)
    }

    fun navigateToLinkPage(link: LinkEntity) {
        viewModel.navigateToLinkPage(_item, link, "", null)
    }

    fun navigateToGameDetailPageById(gameId: String, gameName: String?, childPosition: Int) {
        viewModel.navigateToGameDetailPageById(_item, gameId, gameName, childPosition)
    }

    fun directToLinkPage(linkEntity: LinkEntity) {
        tracker.trackContentCardClick(_item, linkEntity)
        viewModel.navigateToLinkPage(_item, linkEntity, "", null)
    }

    fun navigateToRatingReplyPage(gameId: String, commentId: String) {
        viewModel.navigateToRatingReplyPage(_item, gameId, commentId)
    }

    fun navigateUserHomePage(userId: String) {
        viewModel.navigateUserHomePage(_item, userId)
    }

    fun navigateToInterestedGamePage() {
        trackGameExploreClick("偏好设置")
        viewModel.navigateToInterestedGamePage(_item)
    }

    fun navigateToDiscoveryPage() {
        trackGameExploreClick("全部")
        viewModel.navigateToDiscoveryPage(_item)
    }

    fun trackPluginAreaClick(text: String, game: GameEntity?) {
        tracker.trackPluginAreaClick(text, game)
    }

    fun trackCWRecentlyPlayedClick(text: String, downloadEntity: DownloadEntity?) {
        tracker.trackCWRecentlyPlayedClick(text, downloadEntity)
    }

    fun trackGameExploreClick(
        text: String,
        buttonType: String = "",
        game: GameEntity? = null,
        linkEntity: LinkEntity? = null
    ) {
        tracker.trackGameExploreClick(text, buttonType, game, linkEntity)
    }
}