package com.bc_chat.mine.presenter

import com.bc_chat.bc_base.presenter.UpLoadPicturePresenter
import com.bc_chat.mine.contract.UpdateContract
import com.bc_chat.mine.task.UpdateUserInfoTask
import com.google.gson.JsonObject
import com.zhaohaoting.framework.requset.NetWorkCallBack
import java.lang.Exception

/**
 * author：Created by zhaohaoting on 2019/3/19
 * email：526309416@qq.com
 * desc：
 */
class UpdatePresenter(view: UpdateContract.View) : UpLoadPicturePresenter<UpdateContract.View>(view), UpdateContract.Presenter {

    override fun updateUserInfo(nickname: String?, photo: String?, introduction: String?, province: String?, city: String?, type: Int) {
        taskHelper.execute<Any>(UpdateUserInfoTask(nickname, photo, introduction, province, city), object : NetWorkCallBack<JsonObject>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

            override fun onPostExecuteFailure(task: Any?, exception: Exception?) {
                super.onPostExecuteFailure(task, exception)
                view.dismissLoading(task)
                view.updateFailure()
            }

            override fun onPostExecuteSuccess(task: Any?, data: JsonObject?) {
                view.dismissLoading(task)
                view.updateSuccess(nickname, photo, introduction, province, city,type)
            }
        })
    }
}
