package com.bc_chat.bc_base.presenter

import com.bc_chat.bc_base.contract.SendRedPacketContract
import com.bc_chat.bc_base.entity.ListModel
import com.bc_chat.bc_base.entity.group.MemberBean
import com.bc_chat.bc_base.entity.wallet.SendRedPacketEntity
import com.bc_chat.bc_base.task.GroupMemberDataSource
import com.bc_chat.bc_base.task.SendRedPacketTask
import com.zhaohaoting.framework.abs.presenter.BasePresenter
import com.zhaohaoting.framework.requset.NetWorkCallBack

/**
 * author：Created by zhaohaoting on 2019/7/19
 * email：526309416@qq.com
 * desc：
 */
class SendRedPacketPresenter<VIEW : SendRedPacketContract.View>(view: VIEW) : BasePresenter<VIEW>(view), SendRedPacketContract.Presenter {

    override fun sendRedPacket(type: Int?
                               , receiver_id: String?
                               , amount: String
                               , pay_key: String
                               , group_id: String?
                               , num: Int?
                               , title: String?) {

        taskHelper.execute<Any>(SendRedPacketTask(type, receiver_id, amount, pay_key, group_id, num, title), object : NetWorkCallBack<SendRedPacketEntity>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

            override fun onPostExecuteSuccess(task: Any?, data: SendRedPacketEntity?) {
                view.dismissLoading(task)
                view.sendRedPacketSuccess(data);
            }

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

    override fun groupinfoTask(groupId: String) {
        taskHelper.execute<Any>(GroupMemberDataSource(groupId!!), object : NetWorkCallBack<ListModel<MemberBean>>() {

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

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

            override fun onPostExecuteSuccess(task: Any, memberModel: ListModel<MemberBean>) {
                view.dismissLoading(task)
                view.queryGroupMemberSuccess(memberModel)
            }
        })
    }
}
