package com.gh.gamecenter

import android.app.Application
import com.lightgame.utils.Utils
import com.qq.gdt.action.ActionParam
import com.qq.gdt.action.ActionType
import com.qq.gdt.action.GDTAction
import com.qq.gdt.action.PrivateController
import org.json.JSONObject

object GdtHelper {
    private const val USER_ACTION_SET_ID = "1201041887"
    private const val APP_SECRET_ID = "c29cc5c48cf540c43b4b97363bb09216"

    private const val KS_USER_ACTION_SET_ID = "1201032128"
    private const val KS_APP_SECRET_ID = "9bdbbb81d4e0bd333a2a581f9ee36986"

    @JvmStatic
    fun init(application: Application, channel: String) {
        GDTAction.setPrivateController(object : PrivateController() {
            override fun isCanUsePhoneState(): Boolean {
                return false
            }
        })

        if (channel == "KS_GDT_GHZS_MC01") {
            GDTAction.init(application, KS_USER_ACTION_SET_ID, KS_APP_SECRET_ID, channel)
        } else {
            GDTAction.init(application, USER_ACTION_SET_ID, APP_SECRET_ID, channel)
        }

        GDTAction.start()

        Utils.log("init GdtHelper")
    }

    @JvmStatic
    fun logAction(type: String) {
        when (type) {
            "EVENT_ACTIVE" -> GDTAction.logAction(ActionType.START_APP)
            "active_register" -> GDTAction.logAction(ActionType.REGISTER)
            "EVENT_NEXTDAY_STAY" -> GDTAction.logAction(ActionType.START_APP, JSONObject().apply {
                put(ActionParam.Key.LENGTH_OF_STAY, 1)
            })
        }
    }
}