package com.bc_chat.bc_base.presenter

import com.bc_chat.bc_base.contract.FriendApplyRecordContract
import com.bc_chat.bc_base.entity.FriendApplyRecordBean
import com.bc_chat.bc_base.task.FriendApplyHandlerTask
import com.bc_chat.bc_base.task.FriendApplyRecordTask
import com.google.gson.JsonObject
import com.zhaohaoting.framework.abs.presenter.BasePresenter
import com.zhaohaoting.framework.requset.NetWorkCallBack

/**
 * author：Created by zhaohaoting on 2019/7/19
 * email：526309416@qq.com
 * desc：
 */
class FriendApplyRecordPresenter<VIEW : FriendApplyRecordContract.View>(view: VIEW) : BasePresenter<VIEW>(view), FriendApplyRecordContract.Presenter {
    override fun applyFriendList(page_num: Int, page_size: Int) {
        taskHelper.execute<Any>(FriendApplyRecordTask(page_num, page_size), object : NetWorkCallBack<List<FriendApplyRecordBean>>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

            override fun onPostExecuteSuccess(task: Any?, data: List<FriendApplyRecordBean>?) {
                view.dismissLoading(task)
                view.applyFriendListSuccess(data)
            }

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

    override fun handleFriendApply(id: Int, state: Int) {
        taskHelper.execute<Any>(FriendApplyHandlerTask(id, state), object : NetWorkCallBack<JsonObject>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

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

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


}
