package com.assimilate.alltrans.common

import android.os.Bundle
import com.assimilate.alltrans.MyApp
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase

object FirebaseAnalyticsHelper {
    private val firebaseAnalytics: FirebaseAnalytics by lazy {
        Firebase.analytics
    }

    private fun logCusEvent(eventName: String, params: Map<String, Any?>? = null) {
        val bundle = Bundle().apply {
            params?.forEach { (key, value) ->
                when (value) {
                    is String -> putString(key, value)
                    is Long -> putLong(key, value)
                    is Double -> putDouble(key, value)
                    is Int -> putInt(key, value)
                    else -> throw IllegalArgumentException("Unsupported bundle parameter type")
                }
            }
        }
        //  firebaseAnalytics.logEvent(eventName, bundle)
    }


    fun launchPvEvent() {
        logCusEvent(MyApp.Config.launchPv, null)
    }


    fun homePvEvent(from: String) {
        val params = when (from) {
            "cap" -> mapOf("cap" to 1)
            "create" -> mapOf("cap" to 1)
            else -> {
                null
            }
        }

        logCusEvent(MyApp.Config.homePv, params)
    }

    fun textTransSwitchEvent(from: String) {
        val params = when (from) {
            "cap" -> mapOf("cap" to 1)
            "create" -> mapOf("cap" to 1)
            else -> {
                null
            }
        }

    }


    fun languageChooseEvent(from: String) {
        val params = mapOf(from to 1)
        logCusEvent(MyApp.Config.languageChoose, params)
    }


    fun textTransClickEvent() {
        logCusEvent(MyApp.Config.textTransClick, null)
    }

    fun textTransResultEvent(result: String) {
        val params = mapOf(result to 1)
        logCusEvent(MyApp.Config.textTransResult, params)
    }

    fun textInputEvent() {
        logCusEvent(MyApp.Config.textInput, null)
    }

    fun textTransPasteEvent() {
        logCusEvent(MyApp.Config.textTransPaste, null)
    }

    fun textVoiceClickEvent() {

        logCusEvent(MyApp.Config.textVoiceClick, null)
    }


    fun textVoiceResultEvent(failReason: String) {
        val params = mapOf(failReason to 1)
        logCusEvent(MyApp.Config.textVoiceResult, params)
    }


    fun textTransPlayEvent() {

        logCusEvent(MyApp.Config.textTransPlay, null)
    }

    fun textTransCopyEvent() {
        logCusEvent(MyApp.Config.textTransCopy, null)
    }

    fun textTransShareEvent() {
        logCusEvent(MyApp.Config.textTransShare, null)
    }

    fun textTransLikeEvent() {
        logCusEvent(MyApp.Config.textTransLike, null)
    }


    fun hoverButtonClickEvent() {
        logCusEvent(MyApp.Config.hoverButtonClick, null)
    }

    fun hoverButtonCancelEvent() {
        logCusEvent(MyApp.Config.hoverButtonCancel, null)
    }



}
