package com.bc_chat.bc_base.presenter

import com.bc_chat.bc_base.contract.GroupInfoContract
import com.bc_chat.bc_base.entity.group.Group
import com.bc_chat.bc_base.task.GroupInfoTask
import com.zhaohaoting.framework.abs.presenter.BasePresenter
import com.zhaohaoting.framework.requset.NetWorkCallBack
import java.lang.Exception

/**
 * author：Created by zhaohaoting on 2019/3/8
 * email：526309416@qq.com
 * desc：
 */
open class GroupInfoPresenter<VIEW : GroupInfoContract.View>(view: VIEW) : BasePresenter<VIEW>(view), GroupInfoContract.Presenter {

    override fun groupinfoTask(groupId: String?, isShowDialog: Boolean?) {
        taskHelper.execute<Any>(GroupInfoTask(groupId!!), object : NetWorkCallBack<Group>() {

            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                if (isShowDialog!!) {
                    view.showLoading(task)
                }
            }

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

            override fun onPostExecuteSuccess(task: Any, group: Group) {
                view.dismissLoading(task)
                group.groupId = groupId
                view.groupinfoSuccess(group)
            }
        })
    }
}
