package com.bc_chat.contacts.presenter

import com.bc_chat.bc_base.entity.group.Forbidden
import com.bc_chat.bc_base.presenter.UserInfoPresenter
import com.bc_chat.contacts.contract.GroupMemberManagerContract
import com.bc_chat.contacts.task.*
import com.google.gson.JsonObject
import com.zhaohaoting.framework.requset.NetWorkCallBack
import java.lang.Exception

/**
 * author：Created by zhaohaoting on 2019/3/6
 * email：526309416@qq.com
 * desc：
 */
class GroupMemberManagerPresenter(view: GroupMemberManagerContract.View) : UserInfoPresenter<GroupMemberManagerContract.View>(view), GroupMemberManagerContract.Presenter {
    override fun deleteAdmin(gid: String, cuid: String,userName:String) {
        taskHelper.execute<Any>(DeleteAdminTask(gid, cuid,userName), object : NetWorkCallBack<JsonObject>() {

            override fun onPreExecute(task: Any?) {
                view.showLoading(task)
            }

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

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

    override fun kickout(groupId: String, userName: String, userNames: String, uids: String) {
        taskHelper.execute<Any>(KickoutGroupMemberTask(groupId, userName, userNames, uids), object : NetWorkCallBack<JsonObject>() {
            override fun onPreExecute(task: Any?) {
                view.showLoading(task)
            }

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

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

    override fun forbidden(groupId: String, uids: String, nickname: String, minute: String) {
        taskHelper.execute<Any>(ForbiddenMemberTask(groupId, uids, nickname,minute), object : NetWorkCallBack<JsonObject>() {
            override fun onPreExecute(task: Any?) {
                view.showLoading(task)
            }

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

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

    override fun delForbidden(groupId: String, uids: String) {
        taskHelper.execute<Any>(DelForbiddenMemberTask(groupId, uids), object : NetWorkCallBack<JsonObject>() {
            override fun onPreExecute(task: Any?) {
                view.showLoading(task)
            }

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

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

    override fun forbiddenState(groupId: String) {
        taskHelper.execute<Any>(ForbiddenMemberListTask(groupId), object : NetWorkCallBack<List<Forbidden>>() {

            override fun onPreExecute(task: Any?) {
                view.showLoading(task)
            }

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

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