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.main.page.contract.SettingInfoContract
import okhttp3.MultipartBody

class SettingInfoPresenter : SettingInfoContract.Presenter {
    private val mView: SettingInfoContract.View

    constructor(mView: SettingInfoContract.View) {
        this.mView = mView
    }
    override fun addUserInfo(
        birthday: String,
        invitationCode: String,
        nickname: String,
        sex: String,
        headImage: MultipartBody.Part?
    ) {
        ApiClient.homeApi.addUserInfo(birthday, invitationCode, nickname, sex, headImage)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<Any>() {
                override fun onSuccess(result: Any?) {
                   mView.addInfoSuc()
                }

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

    override fun addUserNoHeadImg(
        birthday: String,
        invitationCode: String,
        nickname: String,
        sex: String
    ) {
        ApiClient.homeApi.addUserInfoNoHeadImg(birthday, invitationCode, nickname, sex)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<Any>() {
                override fun onSuccess(result: Any?) {
                    mView.addInfoSuc()
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    mView.addInfoFail()
                }
            })
    }
}