package com.gh.gamecenter.common.utils

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


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

    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 logHaloSelfNightModeOsSwitch(isOn: Boolean) {
        val json = json {
            "event" to "halo_self_night_mode_os_switch"
            "is_on" to isOn
            parseAndPutMeta().invoke(this)
        }
        log(json, "event", false)
    }
}