package com.zxhl.cms.utils

import android.text.TextUtils
import com.zxhl.cms.ad.upload.model.Response
import com.zxhl.cms.net.ApiClient.userInfoAPi
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.uc.UserInfo

/**
 * Created by gaoleichao on 2021/8/25
 */
object UserDataUtils {

    fun updateUserInfo(callback: AdCallback<String>?) {
        userInfoAPi.userInfo.compose<Response<UserInfo>>(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<UserInfo>() {
                override fun onSuccess(result: UserInfo) {
                    SettingPreference.saveUserInfo(result)
                    SettingPreference.setFlowTag(result.flowTag)
                    SettingPreference.setUserName(result.nickname)
                    SettingPreference.setUserHeadImg(result.headImage)
                    SettingPreference.setUserCoinNum(result.ava)
                    SettingPreference.setIsNewUser(result.isNewUser)
                    callback?.onResult(0, "成功")
                }

                override fun onFailure(e: Throwable, code: String, errorMsg: String) {
                    callback?.onResult(-1, "成功")
                }
            })
    }
}