package com.ym.modulecommon.utils

import com.ym.modulecommon.AdConstant
import com.ym.modulecommon.net.EventApiClient
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import org.json.JSONObject

object BlackBoxEventUtils {

    fun onEventBlackBox(blackBox: String) {
        val jsonObj = JSONObject()
        jsonObj.put("event", "")
        jsonObj.put("action", "checkDevice")
        jsonObj.put("data", "")
        apiClient(jsonObj, blackBox)
    }

    private fun apiClient(data: JSONObject, blackBox: String) {
        val str = data.toString()
        LogUtils.d("EventUtils", str)
        val key = AESUtils.encrypt(str)
        LogUtils.d("EventUtils", key)
        val params = HashMap<String, String>()
        params.put(AdConstant.Device.blackBox, blackBox)
        PhoneUtils.addOtherParams(params)
        EventApiClient.adApi.requestEvent("behavior", key).subscribeOn(Schedulers.io()).subscribe(object : Observer<Any> {
            override fun onComplete() {}
            override fun onSubscribe(d: Disposable) {}
            override fun onNext(t: Any) {}
            override fun onError(e: Throwable) {}
        })
    }
}