package com.bc_chat.bc_base.presenter

import com.bc_chat.bc_base.contract.UserInfoContract
import com.bc_chat.bc_base.entity.User
import com.bc_chat.bc_base.task.UserInfoTask
import com.zhaohaoting.framework.abs.presenter.BasePresenter
import com.zhaohaoting.framework.requset.NetWorkCallBack
import java.lang.Exception

/**
 * author：Created by zhaohaoting on 2019/3/6
 * email：526309416@qq.com
 * desc：获取用户信息
 */
open class UserInfoPresenter<VIEW : UserInfoContract.View>(view: VIEW) : BasePresenter<VIEW>(view), UserInfoContract.Presenter {

    override fun userInfoTask(cuid: String, isShowDialog: Boolean?) {
        taskHelper.execute<Any>(UserInfoTask(cuid), object : NetWorkCallBack<User>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                if (isShowDialog!!) {
                    view.showLoading(task)
                }
            }

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

            override fun onPostExecuteSuccess(task: Any?, data: User) {
                view.dismissLoading(task)
                view.userInfoSuccess(data)
            }
        })
    }
}
