package com.bc_chat.contacts.presenter

import com.bc_chat.bc_base.presenter.UpLoadPicturePresenter
import com.bc_chat.contacts.contract.CreateGroupContract
import com.bc_chat.contacts.task.CreateGroupTask
import com.google.gson.JsonObject
import com.zhaohaoting.framework.requset.NetWorkCallBack

/**
 * author：Created by zhaoaoting on 2019/3/6
 * email：526309416@qq.com
 * desc：创建群
 */
open class CreateGroupPresenter(view: CreateGroupContract.View) : UpLoadPicturePresenter<CreateGroupContract.View>(view), CreateGroupContract.Presenter {
    override fun createGroup(groupName: String, userName: String, uids: String, photo: String?) {
        taskHelper.execute<Any>(CreateGroupTask(groupName, userName, uids, photo), 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.createGroupFailure(exception)
            }

            override fun onPostExecuteSuccess(task: Any?, data: JsonObject?) {
                view.dismissLoading(task)
                data?.let {
                    val groupId = it.get("groupId").asString
                    view.createGroupSuccess(groupId)
                }
            }
        })
    }
}
