package com.bc_chat.contacts.presenter

import com.bc_chat.bc_base.utils.Const
import com.bc_chat.contacts.contract.AddFriendContract
import com.bc_chat.contacts.task.AddFriendTask
import com.google.gson.JsonObject
import com.zhaohaoting.framework.abs.presenter.BasePresenter
import com.zhaohaoting.framework.requset.NetWorkCallBack
import com.zhaohaoting.framework.utils.observer.ObserverManager
import java.lang.Exception

/**
 * author：Created by zhaoaoting on 2019/3/6
 * email：526309416@qq.com
 * desc：添加好友
 */
open class AddFriendPresenter<VIEW : AddFriendContract.View>(view: VIEW) : BasePresenter<VIEW>(view), AddFriendContract.Presenter {

    override fun addFriend(cuid: String,remark:String) {
        taskHelper.execute<Any>(AddFriendTask(cuid,remark), 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.addFriendFailure(exception)
            }

            override fun onPostExecuteSuccess(task: Any?, data: JsonObject?) {
                view.dismissLoading(task)
                view.addFriendSuccess(cuid)
            }
        })
    }
}
