package com.adealink.weparty.stat

import android.content.Context
import com.adealink.frame.aab.util.getCompatString
import com.adealink.frame.base.AppBase
import com.adealink.frame.locale.country.getCountryCode
import com.adealink.frame.locale.language.languageManager
import com.adealink.frame.statistics.IStatConfig
import com.adealink.frame.statistics.ReportType
import com.adealink.frame.statistics.StatClientError
import com.adealink.frame.util.safeToLong
import com.adealink.weparty.App
import com.adealink.weparty.R
import com.adealink.weparty.channel.getChannel
import com.adealink.weparty.debug.DebugPrefs.testDeviceId
import com.adealink.weparty.module.profile.ProfileModule
import kotlin.text.ifEmpty

class StatConfig : IStatConfig {

//    private val statHttpService by lazy {
//        App.instance.networkService.getReportHttpService(ServerStatHttpService::class.java)
//    }

    override val ctx: Context
        get() = App.instance
    override val app: String
        get() = getCompatString(R.string.app_name)
    override val uid: Long
        get() = ProfileModule.getMyUid().safeToLong()
    override val deviceId: String
        get() = if (AppBase.isRelease) {
            App.instance.deviceIdService.getMemOldDeviceId()
        } else {
            testDeviceId.ifEmpty { App.instance.deviceIdService.getMemOldDeviceId() }
        }
    override val countryCode: String
        get() = getCountryCode()
    override val languageCode: String
        get() = languageManager?.getLanguageCode() ?: ""
    override val appChannel: String
        get() = getChannel()

    override val defaultReportChannels =
        //listOf(ReportType.FIREBASE, ReportType.ADJUST)
        listOf(ReportType.ADJUST)
    override val skipReport: Boolean
        get() = !AppBase.isRelease

    override fun reportClientError(statClientError: StatClientError?) {
        if (statClientError == null) {
            return
        }
    }

}