package com.gh.gamecenter.feedback.utils

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.JSONObject

object NewFlatLogUtils {
    private const val KEY_EVENT = "event"

    private fun log(jsonObject: JSONObject, logStore: String = "event", uploadImmediately: Boolean = false) {
        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
        }
    }

    // 意见反馈-分类页面提交按钮点击事件
    fun logFeedbackCommit(type: String, contentType: String, content: String) {
        val json = json {
            KEY_EVENT to "feedback_commint"
            "type" to type
            "content_type" to contentType
            "content" to content
            parseAndPutMeta().invoke(this)
        }
        log(json)
    }
}