package com.bc_chat.contacts.presenter

import com.bc_chat.contacts.contract.ReportContract
import com.bc_chat.contacts.task.ReportTask
import com.google.gson.JsonObject
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 ReportPresenter<VIEW : ReportContract.View>(view: VIEW) : BasePresenter<VIEW>(view), ReportContract.Presenter {

    override fun report(cuid: String?, reason: String?) {
        taskHelper.execute<Any>(ReportTask(cuid, reason), 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.reportFailure(exception)
            }

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