package com.bc_chat.bc_base.presenter

import com.bc_chat.bc_base.contract.ChatRedPacketContract
import com.bc_chat.bc_base.entity.wallet.ChatRedPacketDetailEntity
import com.bc_chat.bc_base.entity.wallet.OpenRedPacketEntity
import com.bc_chat.bc_base.task.ChatRedPacketDetailTask
import com.bc_chat.bc_base.task.OpenRedPacketTask
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 ChatRedPacketPresenter<VIEW : ChatRedPacketContract.View>(view: VIEW) : BasePresenter<VIEW>(view), ChatRedPacketContract.Presenter {

    override fun openRedPacket(packet_id: String) {
        taskHelper.execute<Any>(OpenRedPacketTask(packet_id), object : NetWorkCallBack<OpenRedPacketEntity>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

            override fun onPostExecuteSuccess(task: Any?, data: OpenRedPacketEntity?) {
                view.dismissLoading(task)
                redPacketDetail(packet_id)
            }

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

    override fun redPacketDetail(packet_id: String) {
        taskHelper.execute<Any>(ChatRedPacketDetailTask(packet_id), object : NetWorkCallBack<ChatRedPacketDetailEntity>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

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

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

//    override fun isOpenRedPacket(packet_id: String) {
//        taskHelper.execute<Any>(RedPacketIsOpenTask(packet_id), object : NewNetWorkCallBack<JsonObject>() {
//            override fun onPreExecute(task: Any?) {
//                super.onPreExecute(task)
//                view.showLoading(task)
//            }
//
//            override fun onPostExecuteSuccess(task: Any?, data: JsonObject?) {
//                view.dismissLoading(task)
//                redPacketDetail(packet_id);
//            }
//
//            override fun onPostExecuteFailed(task: Any?, exception: RequestException?) {
//                view.dismissLoading(task)
//                if (exception?.code == HttpCode.EXCEPTION_CODE_1012) {
//                    openRedPacket(packet_id);
//                } else if (exception?.code == HttpCode.EXCEPTION_CODE_1011) {
//                    redPacketDetail(packet_id)
//                } else {
//                    showException(exception)
//                }
//            }
//        })
//    }

}
