package com.ydl.ydlnet.utils

import android.annotation.SuppressLint
import android.util.Log
import com.ydl.ydlnet.builder.api.ApiUtil
import com.ydl.ydlnet.builder.bean.ApiErrorActionBean
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * Created by Ykai on 2021/3/15.
 */
class ApiErrorCountUtils {
    companion object {
        private const val TAG: String = "ActionCountUtils"

        /**
         * 接口返回错误埋点调用该方法
         * @param partId pardId-ydl_user_error_business
         * @param position error_log
         * @param sign1 访问接口对应的参数
         * @param sign2 接口返回的错误信息
         */
        fun baiDuCount(
            partId: String,
            position: String,
            sign1: String,
            sign2: String
        ) {
            val actionDataParams = ApiErrorActionBean.Builder()
            actionDataParams.partId = partId
            actionDataParams.position = position
            actionDataParams.sign1 = sign1
            actionDataParams.sign2 = sign2
            //请求
            request(actionDataParams.build())
        }

        /**
         * 传入ActionDataParams参数，访问接口
         */
        @SuppressLint("CheckResult")
        private fun request(actionDataBean: ApiErrorActionBean) {
            try {
                ApiUtil.actionDataCount(actionDataBean)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe({
                        Log.i(TAG, it.data)
                    }) {
                        Log.i(TAG, it.toString())
                    }
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }
}