package com.gh.common.util

import com.gh.gamecenter.common.json.JsonObjectBuilder
import com.gh.gamecenter.common.json.json
import com.gh.gamecenter.common.loghub.LoghubUtils
import com.gh.gamecenter.common.utils.LogUtils
import com.lightgame.utils.Utils
import org.json.JSONArray
import org.json.JSONObject

/**
 * 新平铺埋点工具类
 * 因为新的埋点都要平铺字段，所以新建此类，新埋点在此类添加即可
 */
object NewFlatLogUtils {

    private fun log(jsonObject: JSONObject, logStore: String, uploadImmediately: Boolean) {
        Utils.log("NewFlatLogUtils", jsonObject.toString(4))
        LoghubUtils.log(jsonObject, logStore, uploadImmediately, true)
    }

    private fun parseAndPutMeta(): JsonObjectBuilder.() -> Unit = {
        val meta = LogUtils.getNewMetaObject()
        val metaKeys = meta.keys()
        while (metaKeys.hasNext()) {
            val key: String = metaKeys.next().toString()
            val value = meta.getString(key)
            key to value
        }
    }

    // 畅玩助手相关事件(下载弹窗展示事件/隐私政策点击事件/下载点击事件/授权弹窗展示事件/更新弹窗展示事件)
    // 畅玩管理删除游戏弹窗展示事件/畅玩管理-畅玩广场入口点击事件/退出畅玩助手提示弹窗展示事件
    @JvmStatic
    fun logHaloFunEvent(event: String) {
        val json = json {
            "event" to event
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 关联游戏跳转icon点击事件
    @JvmStatic
    fun logHaloFunGameDetailJumpClick(downloadStatus: String, gameId: String) {
        val json = json {
            "event" to "halo_fun_game_detail_jump_click"
            "download_state" to downloadStatus
            "game_id" to gameId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 下载完成提示条点击事件
    @JvmStatic
    fun logHaloFunDownloadCompleteTipClick(buttonType: String, gameId: String) {
        val json = json {
            "event" to "halo_fun_download_complete_tip_click"
            "button_type" to buttonType
            "game_id" to gameId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 畅玩助手更新弹窗点击事件
    @JvmStatic
    fun logHaloFunUpdateDialogClick(dialogType: String, buttonType: String) {
        val json = json {
            "event" to "halo_fun_update_dialog_click"
            "dialog_type" to dialogType
            "button_type" to buttonType
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 畅玩管理展示事件
    @JvmStatic
    fun logHaloFunManageShow(entrance: String) {
        val json = json {
            "event" to "halo_fun_manage_show"
            "entrance" to entrance
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 畅玩管理-最近在玩板块展示管理事件
    @JvmStatic
    fun logHaloFunManageRecentGameSwitch(isOn: Boolean) {
        val json = json {
            "event" to "halo_fun_manage_recent_game_switch"
            "is_on" to isOn
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 畅玩管理删除游戏弹窗点击事件
    @JvmStatic
    fun logHaloFunManageGameDeleteDialogClick(buttonType: String, gamesArray: JSONArray) {
        val json = json {
            "event" to "halo_fun_manage_game_delete_dialog_click"
            "button_type" to buttonType
            "games_array" to gamesArray
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 退出畅玩助手提示弹窗反馈收集事件
    @JvmStatic
    fun logHaloFunGameExitDialogSubmitClick(gameId: String, detail: String, typeTags: JSONArray) {
        val json = json {
            "event" to "halo_fun_game_exit_dialog_submit_click"
            "game_id" to gameId
            "detail" to detail
            "type_tags" to typeTags
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 搜索-点击热门标签
    @JvmStatic
    fun logSearchHotTagClick(
        tag: String,
        linkType: String,
        linkId: String,
        linkText: String
    ) {
        val json = json {
            "event" to "search_click_hot_tag"
            "tag" to tag
            "link_type" to linkType
            "link_id" to linkId
            "link_text" to linkText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //版块点击内容卡片
    @JvmStatic
    fun logBlockGameContentCardClick(
        blockId: String,
        blockName: String,
        linkType: String,
        linkId: String,
        linkText: String
    ) {
        val json = json {
            "event" to "block_game_content_card_click"
            "block_id" to blockId
            "block_name" to blockName
            "link_type" to linkType
            "link_id" to linkId
            "link_text" to linkText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //首页点击内容卡片
    @JvmStatic
    fun logHomeGameContentCardClick(
        linkType: String,
        linkId: String,
        linkText: String
    ) {
        val json = json {
            "event" to "home_game_content_card_click"
            "link_type" to linkType
            "link_id" to linkId
            "link_text" to linkText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏详情点击内容卡片
    @JvmStatic
    fun logGameDetailGameContentCardClick(
        title: String,
        gameName: String,
        gameId: String,
        linkType: String,
        linkId: String,
        linkText: String
    ) {
        val json = json {
            "event" to "game_detail_game_content_card_click"
            "title" to title
            "game_name" to gameName
            "game_id" to gameId
            "link_type" to linkType
            "link_id" to linkId
            "link_text" to linkText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //浏览自定义栏目
    @JvmStatic
    fun logGameDetailColumnOrderingView(
        title: String,
        gameName: String,
        gameId: String
    ) {
        val json = json {
            "event" to "game_detail_column_ordering_view"
            "title" to title
            "game_name" to gameName
            "game_id" to gameId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //我的游戏tab点击
    @JvmStatic
    fun logMyGameTabClick(tab: String) {
        val json = json {
            "event" to "game_self_tab_click"
            "tab_name" to tab
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //玩过tab开启游戏时长
    @JvmStatic
    fun logMyGameTabOpenTimeLongClick() {
        val json = json {
            "event" to "game_self_played_time_statistics_button_click"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏时长统计弹窗点击事件
    @JvmStatic
    fun logGameTimeLongDialogClick(content: String) {
        val json = json {
            "event" to "game_self_played_time_statistics_dialog_click"
            "text" to content
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //玩过tab游戏卡片点击事件
    @JvmStatic
    fun logMyGamePlayedTabGameCardClick(content: String, gameId: String, gameName: String) {
        val json = json {
            "event" to "game_self_played_game_card_click"
            "text" to content
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //玩过tab清除游戏记录
    @JvmStatic
    fun logMyGamePlayedTabClearGameClick(gameId: String, gameName: String) {
        val json = json {
            "event" to "game_self_played_history_clear_click"
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //玩过tab清除游戏记录弹窗点击事件
    @JvmStatic
    fun logMyGamePlayedTabClearGameDialogClick(text: String, gameId: String, gameName: String) {
        val json = json {
            "event" to "game_self_played_history_clear_dialog_click"
            "text" to text
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //关注tab关注游戏 我的游戏-关注 ，点击热门游戏推荐时上报
    @JvmStatic
    fun logMyGameFollowTabHotGameClick(content: String, gameId: String, gameName: String) {
        val json = json {
            "event" to "game_self_follow_hot_recommend_click"
            "text" to content
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //关注tab游戏卡片点击事件
    fun logMyGameFollowTabGameCardClick(content: String, gameId: String, gameName: String) {
        val json = json {
            "event" to "game_self_follow_game_card_click"
            "text" to content
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //取消关注弹窗点击事件
    @JvmStatic
    fun logMyGameCancelFollowDialogClick(content: String, gameId: String, gameName: String) {
        val json = json {
            "event" to "game_self_follow_cancel_dialog_click"
            "text" to content
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //预约tab游戏卡片点击事件
    @JvmStatic
    fun logMyGameReserveTabGameCardClick(content: String, gameId: String, gameName: String) {
        val json = json {
            "event" to "game_self_appointment_game_card_click"
            "text" to content
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //取消预约弹窗点击事件
    @JvmStatic
    fun logMyGameCancelReserveDialogClick(content: String, gameId: String, gameName: String) {
        val json = json {
            "event" to "game_self_appointment_cancel_dialog_click"
            "text" to content
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 搜索-点击搜索榜单
    @JvmStatic
    fun logSearchClickRank(
        rankName: String,
        rankSequence: String,
    ) {
        val json = json {
            "event" to "search_click_rank"
            "rank_name" to rankName
            "rank_sequence" to rankSequence
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //点击社区-搜索页返回按钮
    @JvmStatic
    fun logClickSearchReturn(searchKey: String) {
        val json = json {
            "event" to "click_search_return"
            "search_key" to searchKey
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //社区搜索结果浏览
    @JvmStatic
    fun logViewSearchList(stayTime: Long, searchKey: String) {
        val json = json {
            "event" to "view_search_list"
            "stay_time" to stayTime
            "search_key" to searchKey
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //社区搜索tab结果切换事件
    @JvmStatic
    fun logClickSearchTab(searchKey: String, tab: String) {
        val json = json {
            "event" to "click_search_tab"
            "search_key" to searchKey
            "tab_type" to tab
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //点击论坛-搜索页返回按钮
    @JvmStatic
    fun logClickBbsSearchReturn(searchKey: String, bbsId: String) {
        val json = json {
            "event" to "click_bbs_search_return"
            "search_key" to searchKey
            "bbs_id" to bbsId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //论坛搜索结果浏览
    @JvmStatic
    fun logViewBbsSearchList(stayTime: Long, searchKey: String, bbsId: String) {
        val json = json {
            "event" to "view_bbs_search_list"
            "stay_time" to stayTime
            "search_key" to searchKey
            "bbs_id" to bbsId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //新版我的光环触发登录
    @JvmStatic
    fun logHaloSelfLogin() {
        val json = json {
            "event" to "halo_self_login_trigger"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //新版我的光环点击事件
    @JvmStatic
    fun logHaloSelfClick(profile: String, text: String) {
        val json = json {
            "event" to "halo_self_click_v2"
            "profile" to profile
            "text" to text
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //新版我的光环点击切换深色/日间模式
    @JvmStatic
    fun logHaloSelfNightModeClick(type: String) {
        val json = json {
            "event" to "halo_self_night_mode_click"
            "button_type" to type
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //触发关闭深色模式跟随系统切换弹窗
    @JvmStatic
    fun logHaloSelfNightModeOsDialog(buttonText: String) {
        val json = json {
            "event" to "halo_self_night_mode_os_dialog"
            "button_text" to buttonText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //我的发布tab点击事件
    @JvmStatic
    fun logHaloSelfPublishTab(tabName: String) {
        val json = json {
            "event" to "halo_self_publish_tab"
            "tab_name" to tabName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //我的发布内容点击事件
    @JvmStatic
    fun logHaloSelfPublishContent(tabName: String, location: String) {
        val json = json {
            "event" to "halo_self_publish_content"
            "tab_name" to tabName
            "location" to location
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //论坛详情页—置顶栏
    fun logClickForumTopBar(contentType: String, contentId: String, sequence: Int, bbsId: String) {
        val json = json {
            "event" to "click_forum_top_bar"
            "content_type" to contentType
            "content_id" to contentId
            "sequence" to sequence
            "bbs_id" to bbsId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //个人主页-内容
    fun logClickSelfPublish(contentType: String, contentId: String, refUserId: String, tabName: String) {
        val json = json {
            "event" to "click_self_publish"
            "content_type" to contentType
            "content_id" to contentId
            "ref_user_id" to refUserId
            "tab_name" to tabName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏详情页-视频合集内容
    fun logClickGameDetailVideoCategory(contentType: String, contentId: String, refUserId: String) {
        val json = json {
            "event" to "click_game_detail_video_category"
            "content_type" to contentType
            "content_id" to contentId
            "ref_user_id" to refUserId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //进入游戏详情/离开游戏详情
    fun logGameDetailEnterOrExit(event: String, gameName: String, gameId: String) {
        val json = json {
            "event" to event
            "game_name" to gameName
            "game_id" to gameId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //手机号验证弹窗点击事件
    fun logPhoneNumberVerifyDialogClick(entrance: String, text: String) {
        val json = json {
            "event" to "publish_phone_number_verify_dialog_click"
            "entrance" to entrance
            "text" to text
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //手机号验证界面展示事件
    fun logPhoneNumberVerifyDialogShow(entrance: String) {
        val json = json {
            "event" to "publish_phone_number_verify_dialog_show"
            "entrance" to entrance
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }


    //完成手机号验证
    fun logPhoneNumberVerifyDialogSuccess() {
        val json = json {
            "event" to "publish_phone_number_verify_dialog_success"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 进入活动页面
    fun logActivityPageEnter(entrance: String, activityId: String) {
        val json = json {
            "event" to "activity_page_enter"
            "entrance" to entrance
            "activity_id" to activityId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 活动页面浏览
    fun logActivityPageView(interval: Int, activityId: String) {
        val json = json {
            "event" to "activity_page_view"
            "interval" to interval
            "activity_id" to activityId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器更新弹窗展示事件
    @JvmStatic
    fun logSimulatorUpdateAlertShow() {
        val json = json {
            "event" to "simulator_update_pop_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器更新弹窗按钮点击事件
    @JvmStatic
    fun logSimulatorUpdateAlertClick(buttonText: String) {
        val json = json {
            "event" to "simulator_update_pop_click"
            "button_type" to buttonText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器游戏页面展示事件
    @JvmStatic
    fun logSimulatorGamePageShow() {
        val json = json {
            "event" to "simulator_game_page_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器游戏类型Tab展示事件
    @JvmStatic
    fun logSimulatorGamePageTabClick(tabName: String) {
        val json = json {
            "event" to "simulator_game_tag_show"
            "tab_name" to tabName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器游戏卡片点击事件
    @JvmStatic
    fun logSimulatorGameCardClick(buttonText: String) {
        val json = json {
            "event" to "simulator_game_card_click"
            "button_type" to buttonText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器游戏合集点击事件
    @JvmStatic
    fun logSimulatorGameCollectionClick() {
        val json = json {
            "event" to "simulator_game_collection_click"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏删除提示弹窗展示事件
    @JvmStatic
    fun logSimulatorGameDeleteAlertShow() {
        val json = json {
            "event" to "simulator_delete_game_pop_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏删除提示弹窗点击事件
    @JvmStatic
    fun logSimulatorGameDeleteAlertClick(buttonText: String) {
        val json = json {
            "event" to "simulator_delete_game_pop_click"
            "button_type" to buttonText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器管理页面展示事件
    @JvmStatic
    fun logSimulatorManagerClick() {
        val json = json {
            "event" to "simulator_manger_page_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器列表相关点击事件
    fun logSimulatorListClick(buttonText: String, simulatorType: String) {
        val json = json {
            "event" to "simulator_list_click"
            "button_type" to buttonText
            "simulator_name" to simulatorType
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器卸载提示弹窗展示事件
    fun logSimulatorUninstallAlertShow(simulatorType: String) {
        val json = json {
            "event" to "simulator_uninstall_pop_show"
            "simulator_name" to simulatorType
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //模拟器卸载提示弹窗展示事件
    fun logSimulatorUninstallAlertClick(buttonText: String) {
        val json = json {
            "event" to "simulator_uninstall_pop_click"
            "button_type" to buttonText
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //进入发现页面
    fun logDiscoverPageEnter() {
        val json = json {
            "event" to "discover_page_enter"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //离开发现页面
    fun logDiscoverPageQuit(sequence: Int) {
        val json = json {
            "event" to "discover_page_quit"
            "sequence" to sequence
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //发现页面可见事件
    fun logDiscoverPageVisible() {
        val json = json {
            "event" to "discover_page_visible"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //发现页面不可见事件
    fun logDiscoverPageInvisible(sequence: Int) {
        val json = json {
            "event" to "discover_page_invisible"
            "sequence" to sequence
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //页面顶部露出
    fun logDiscoverPageTopVisible(countNum: Int) {
        val json = json {
            "event" to "discover_page_top_visible"
            "count_num" to countNum
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //页面底部停留
    fun logDiscoverPageBottomStay(countNum: Int) {
        val json = json {
            "event" to "discover_page_bottom_stay"
            "count_num" to countNum
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //点击兴趣推荐卡片
    fun logDiscoverPageRecommendedInterestCardClick(sequence: Int, linkText: String, linkType: String, linkId: String) {
        val json = json {
            "event" to "discover_page_recommended_interest_card_click"
            "sequence" to sequence
            "link_text" to linkText
            "link_type" to linkType
            "link_id" to linkId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //点击跳转游戏库
    fun logDiscoverPageJumpGamesLibraries() {
        val json = json {
            "event" to "discover_page_jump_games_libraries"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //触发不感兴趣
    fun logDiscoverPageNotInterest(gameId: String, gameName: String) {
        val json = json {
            "event" to "discover_page_not_interest"
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //跳过广告
    @JvmStatic
    fun logOpenScreenAdSkip(adId: String, linkText: String, linkType: String, linkId: String) {
        val json = json {
            "event" to "open_screen_ad_skip"
            "ad_id" to adId
            "link_text" to linkText
            "link_type" to linkType
            "link_id" to linkId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏单广场浏览时长
    fun logGameCollectSquareStayTime(interval: Long) {
        val json = json {
            "event" to "game_collect_square_stay_time"
            "interval" to interval
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏单浏览时长
    fun logGameCollectStayTime(interval: Long, id: String, title: String) {
        val json = json {
            "event" to "game_collect_stay_time"
            "interval" to interval
            "game_collect_id" to id
            "game_collect_title" to title
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 游戏存档页面展示事件
    fun logGameArchivePageShow(tabName: String) {
        val json = json {
            "event" to "cloud_save_game_save_page_show"
            "tab_name" to tabName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 云存档管理页面展示事件
    fun logCloudArchiveManagePageShow(gameId: String, gameName: String, entrance: String) {
        val json = json {
            "event" to "cloud_save_manage_page_show"
            "game_id" to gameId
            "game_name" to gameName
            "entrance" to entrance
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 云存档Tab页面展示事件
    fun logCloudArchiveTabShow(gameId: String, gameName: String, tabName: String) {
        val json = json {
            "event" to "cloud_save_tab_page_show"
            "game_id" to gameId
            "game_name" to gameName
            "tab_name" to tabName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 存档分享弹窗展示事件
    fun logCloudArchiveShareDialogShow() {
        val json = json {
            "event" to "cloud_save_share_dialog_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 存档分享弹窗点击事件
    fun logCloudArchiveShareDialogClick(buttonType: String) {
        val json = json {
            "event" to "cloud_save_share_dialog_click"
            "button_type" to buttonType
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 存档分享弹窗分享结果事件
    fun logCloudArchiveShareDialogResult(shareResult: String) {
        val json = json {
            "event" to "cloud_save_share_dialog_result"
            "share_result" to shareResult
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 存档删除弹窗展示事件
    fun logCloudArchiveDeleteDialogShow() {
        val json = json {
            "event" to "cloud_save_delete_dialog_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 存档删除弹窗点击事件
    fun logCloudArchiveDeleteDialogClick(buttonType: String) {
        val json = json {
            "event" to "cloud_save_delete_dialog_click"
            "button_type" to buttonType
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 上传存档弹窗展示事件
    fun logCloudArchiveUploadDialogShow() {
        val json = json {
            "event" to "cloud_save_upload_dialog_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 上传存档弹窗点击事件
    fun logCloudArchiveUploadDialogClick(buttonType: String) {
        val json = json {
            "event" to "cloud_save_upload_dialog_click"
            "button_type" to buttonType
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 畅玩助手下载提示弹窗展示事件
    fun logCloudArchiveVSpaceDownloadDialogShow() {
        val json = json {
            "event" to "cloud_save_halo_fun_download_dialog_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 畅玩助手下载提示弹窗点击事件
    fun logCloudArchiveVSpaceDownloadDialogClick(buttonType: String) {
        val json = json {
            "event" to "cloud_save_halo_fun_download_dialog_click"
            "button_type" to buttonType
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 游戏下载提示弹窗展示事件
    fun logCloudArchiveGameDownloadDialogShow() {
        val json = json {
            "event" to "cloud_save_game_download_dialog_show"
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 游戏下载提示弹窗点击事件
    fun logCloudArchiveGameDownloadDialogClick(buttonType: String) {
        val json = json {
            "event" to "cloud_save_game_download_dialog_click"
            "button_type" to buttonType
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 推荐游戏页面下载游戏事件
    fun logCloudArchiveRecommendGameDownload(gameId: String, gameName: String) {
        val json = json {
            "event" to "cloud_save_recommend_game_page_download"
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 搜索功能关键词上传事件
    fun logCloudArchiveSearchKeyUpload(gameId: String, gameName: String, key: String) {
        val json = json {
            "event" to "cloud_save_search_key_upload"
            "game_id" to gameId
            "game_name" to gameName
            "key" to key
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 云存档Tab展示事件/云存档Tab展示事件
    fun logCloudArchiveGameDetailTabRelated(event: String, gameId: String, gameName: String) {
        val json = json {
            "event" to event
            "game_id" to gameId
            "game_name" to gameName
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 云存档下载/使用事件
    fun logCloudArchiveDownloadOrApply(archiveName: String, entrance: String) {
        val json = json {
            "event" to "cloud_save_download"
            "cloud_save_name" to archiveName
            "entrance" to entrance
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 存档覆盖风险提示弹窗展示事件/存档覆盖风险提示弹窗点击事件
    fun logCloudArchiveApplyDialogRelated(event: String, buttonType: String = "") {
        val json = json {
            "event" to event
            if (buttonType.isNotBlank()) {
                "button_type" to buttonType
            }
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 进入发现页详情
    fun logDiscoverDetailPageEnter(entrance: String, blockName: String = "") {
        val json = json {
            "event" to "discover_detail_page_enter"
            "entrance" to entrance
            if (blockName.isNotBlank()) {
                "block_name" to blockName
            }
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 点击设置偏好
    fun logInterestedGameClick(entrance: String, blockName: String = "") {
        val json = json {
            "event" to "discover_preference_settings_click"
            "entrance" to entrance
            if (blockName.isNotBlank()) {
                "block_name" to blockName
            }
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 进入游戏偏好页面
    fun logInterestedGamePageEnter(frequency: String, prefer: String, tendency: String, typeTags: JSONArray) {
        val json = json {
            "event" to "discover_preference_game_page_enter"
            "frequency" to frequency
            "prefer" to prefer
            "tendency" to tendency
            "type_tags" to typeTags
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 离开游戏偏好页面
    fun logInterestedGamePageExit(
        frequency: String,
        prefer: String,
        tendency: String,
        typeTags: JSONArray,
    ) {
        val json = json {
            "event" to "discover_preference_game_page_quit"
            "frequency" to frequency
            "prefer" to prefer
            "tendency" to tendency
            "type_tags" to typeTags
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 浏览游戏偏好页面
    fun logInterestedGamePageBrowse(
        frequency: String,
        prefer: String,
        tendency: String,
        typeTags: JSONArray,
        interval: Long
    ) {
        val json = json {
            "event" to "discover_preference_game_view"
            "frequency" to frequency
            "prefer" to prefer
            "tendency" to tendency
            "type_tags" to typeTags
            "interval" to interval
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 展开感兴趣的分类弹窗
    fun logInterestedGameTypeDialogShow(typeTags: JSONArray) {
        val json = json {
            "event" to "discover_preference_type_tags_dialog_show"
            "type_tags" to typeTags
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 关闭感兴趣的分类弹窗
    fun logInterestedGameTypeDialogClose(typeTags: JSONArray) {
        val json = json {
            "event" to "discover_preference_type_tags_dialog_close"
            "type_tags" to typeTags
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    // 浏览感兴趣的分类弹窗
    fun logInterestedGameTypeDialogBrowse(typeTags: JSONArray, interval: Long) {
        val json = json {
            "event" to "discover_preference_type_tags_dialog_view"
            "type_tags" to typeTags
            "interval" to interval
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏详情-游戏单推荐，点击右上角进入游戏单广场时触发
    fun logGameDetailGameListRecommendSquareJump(gameName: String, gameId: String) {
        val json = json {
            "event" to "game_detail_game_list_recommend_square_jump"
            "game_name" to gameName
            "game_id" to gameId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }

    //游戏详情-专题推荐，点击右上角时触发
    fun logGameDetailColumnRecommendUpperRightClick(
        gameName: String,
        gameId: String,
        buttonType: String,
        columnName: String,
        columnId: String,
        linkText: String,
        linkType: String,
        linkId: String
    ) {
        val json = json {
            "event" to "game_detail_column_recommend_upper_right_click"
            "game_name" to gameName
            "game_id" to gameId
            "button_type" to buttonType
            "column_name" to columnName
            "column_id" to columnId
            "link_text" to linkText
            "link_type" to linkType
            "link_id" to linkId
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }
}