package com.zxhl.main.page.presenter

import android.util.Log
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.uc.UserInfo
import com.zxhl.main.page.contract.VoiceContract
import okhttp3.MultipartBody

class VoicePresenter:VoiceContract.Presenter {
    private val mView: VoiceContract.View


    constructor(mView: VoiceContract.View) {
        this.mView = mView
    }

    override fun updateUserVoice(voiceTime: String, voice: MultipartBody.Part?) {
        ApiClient.homeApi.updateUserVoice(
            voiceTime,
            voice
        )
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<UserInfo>() {
                override fun onSuccess(result: UserInfo?) {
                    mView.updateVoiceSuc(result)
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    Log.e("MXL", "ERROR" + code + errorMsg)
                    mView.updateVoiceFail()
                }
            })
    }
}