package com.bc_chat.contacts.presenter

import com.bc_chat.contacts.contract.UserManagerContract
import com.bc_chat.contacts.task.BlackTask
import com.bc_chat.contacts.task.DeleteUserTask
import com.google.gson.JsonObject
import com.zhaohaoting.framework.requset.NetWorkCallBack
import java.lang.Exception

/**
 * author：Created by zhaoaoting on 2019/3/6
 * email：526309416@qq.com
 * desc：黑名单
 */
class UserManagerPresenter(view: UserManagerContract.View) : ReportPresenter<UserManagerContract.View>(view), UserManagerContract.Presenter {

    override fun blackSetting(cuid: String?, isBlack: Int) {

        taskHelper.execute<Any>(BlackTask(cuid), 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.blackSettingFailure(exception)
            }

            override fun onPostExecuteSuccess(task: Any?, data: JsonObject?) {
                view.dismissLoading(task)
                view.blackSettingfSuccess(isBlack)
            }
        })
    }
    override fun deleteFriend(cuid: String?) {

        taskHelper.execute<Any>(DeleteUserTask(cuid), 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.deleteFriendFailure(exception)
            }

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