package pxds.iqiv.ioih.gxph

import com.blankj.utilcode.util.SPUtils
import com.test.basd.supercleanermax.R
import pxds.Tmuv
import pxds.lmmd.zmwf.Egac
import pxds.lmmd.zmwf.Khko.string
import pxds.lmmd.zmwf.Uloz
import pxds.vazp.Uenj
import pxds.vazp.Uenj.Companion.getActionPushInterval

object Euzn {

    private val TAG = R.string.ވކޘގޛ_D.string()

    fun isPush(actionId: Int, Oxfj: EventParams? = null): Boolean {
        val configBean: Uenj = Uloz.getSpConfigBean()

        if (!newUserPush(configBean.newuser_avoid_time)) {
            Egac.logDebug(TAG, R.string.ނތނޥލ_D.string())
            return false
        }

        val interval = configBean.all_push_interval
        if (!canPushNextTime(interval)) {
            Egac.logDebug(TAG, R.string.ސޞޏލރ_D.string())
            return false
        }

        val pushInterval = configBean.getActionPushInterval(actionId)
        if (!actionTypeCanPsh(actionId, pushInterval)) {
            Egac.logDebug(TAG, R.string.ޟޛޚޓޣ_D.string())
            return false
        }

        val isResumed = Tmuv.PAUSED_VALUE == 1
        Egac.logDebug(TAG, R.string.ގބއޏޜ_D.string((isResumed).toString()))
        if (isResumed) {
            Egac.logDebug(TAG, R.string.ޏޝޗޚޓ_D.string())
            return false
        }
        Egac.logDebug(TAG, R.string.ޤޜޜކގ_D.string())

        return true
    }

    fun canPushNextTime(interval: Int): Boolean {
        val lastPushTime = SPUtils.getInstance().getLong(R.string.ޤޛފގޖ_D.string(), 0)
        val haveInterval = (System.currentTimeMillis() - lastPushTime) / 1000
        return haveInterval > interval
    }

    fun newUserPush(newUserAvoidTime: Int): Boolean {
        val firstLaunchTime = SPUtils.getInstance().getLong(R.string.ޑޅވޠއ_D.string(), 0)
        val haveFirstLaunchTime = (System.currentTimeMillis() - firstLaunchTime) / 1000
        val flag = haveFirstLaunchTime > newUserAvoidTime
        return flag
    }

    private fun actionTypeCanPsh(actionId: Int, pushInterval: Int = 0): Boolean {
        val lastTypePushTime = SPUtils.getInstance().getLong(actionId.toString(), 0L)
        val actionInterval = (System.currentTimeMillis() - lastTypePushTime) / 1000
        Egac.logDebug(TAG, R.string.ޓޟބޕޝ_D.string((actionId).toString(), (actionInterval).toString(), (pushInterval).toString()))
        return actionInterval > pushInterval
    }
}