package com.bc_chat.contacts.presenter

import com.bc_chat.contacts.contract.GroupManagerContract
import com.bc_chat.contacts.task.DissolutionGroupTask
import com.bc_chat.contacts.task.ForbiddenTask
import com.bc_chat.contacts.task.LordNoticeTopTask
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：
 */
class GroupManagerPresenter(view: GroupManagerContract.View) : BasePresenter<GroupManagerContract.View>(view), GroupManagerContract.Presenter {

    /**
     * 解散
     */
    override fun dissolutionGroup(groupId: String?, userName: String?) {
        taskHelper.execute<Any>(DissolutionGroupTask(groupId, userName), 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.dissolutionGroupSuccess()
            }

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



    override fun forbidden(groupId: String, is_banned: Int) {
        taskHelper.execute<Any>(ForbiddenTask(groupId, is_banned), 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.forbiddenSuccess(is_banned)
            }

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

    override fun lordNoticeTop(groupId: String, is_top: Int) {
        taskHelper.execute<Any>(LordNoticeTopTask(groupId, is_top), 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.lordNoticeTopSuccess(is_top)
            }

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