package com.zxhl.cms.utils

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.setUserName(result.nickname)
                    SettingPreference.setUserDesc(result.description)
                    SettingPreference.setIsVip("${result.memberType}")
                    SettingPreference.setMemberEndTime(result.memberEndTime)
                    SettingPreference.setUserHeadImg(result.headImage)
                    SettingPreference.setHasData("${result.hasData}")
                    callback?.onResult(0, "成功")
                }

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