package com.zxbw.modulemain.box.presenter

import com.zxbw.modulemain.box.contract.LotteryContract
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.box.*

class LotteryPresenter : LotteryContract.Presenter {
    private val mView: LotteryContract.View

    constructor(mView: LotteryContract.View) {
        this.mView = mView
    }

    override fun testLottery(boxid: String?) {
        ApiClient.homeApi.testLottery(boxid ?: "")
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<LotteryEntity>() {
                override fun onSuccess(result: LotteryEntity?) {
                    if (result != null) {
                        mView.setTestLotterResult(result)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }

    override fun oneLottery(boxid: String?) {
        ApiClient.homeApi.oneLottery(boxid ?: "")
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<OneLotteryEntity>() {
                override fun onSuccess(result: OneLotteryEntity?) {
                    if (result != null) {
                        mView.setOneLotterResult(result)
//                        mView.setPropsCardList(null,result.card)
//                        getPropsCardList(boxid, result.card)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }

    override fun fiveLottery(boxid: String?) {
        ApiClient.homeApi.fiveLottery(boxid ?: "")
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<FiveLotteryEntiy>() {
                override fun onSuccess(result: FiveLotteryEntiy?) {
                    if (result != null) {
                        mView.setFiveLotterResult(result)
                        mView.setPropsCardList(null,result.card)
//                        getPropsCardList(boxid, result.card)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }

    override fun epicCardLottery(boxid: String?) {
        ApiClient.homeApi.epicCardLottery(boxid ?: "")
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<FiveLotteryEntiy>() {
                override fun onSuccess(result: FiveLotteryEntiy?) {
                    if (result != null) {
                        mView.setEpicCardLotteryResult(result)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }

    override fun getPropsCardList(boxid: String?, cardEntity: PropsCardEntity?) {
        ApiClient.homeApi.getPropsCardList(boxid ?: "")
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<PropsCardList?>() {
                override fun onSuccess(result: PropsCardList?) {
                    mView.setPropsCardList(result, cardEntity)
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    mView.setPropsCardList(null, null)
                }
            })
    }

    override fun rePumpingOneLottery(boxid: String?, depotIds: String) {
        ApiClient.homeApi.rePumpingOneLottery(boxid ?: "", depotIds)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<OneLotteryEntity>() {
                override fun onSuccess(result: OneLotteryEntity?) {
                    if (result != null) {
                        mView.setOneLotterResult(result)
                        // getPropsCardList(boxid, null)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }

    override fun rePumpingFiveLottery(boxid: String?, depotIds: String) {
        ApiClient.homeApi.rePumpingFiveLottery(boxid ?: "", depotIds)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<FiveLotteryEntiy>() {
                override fun onSuccess(result: FiveLotteryEntiy?) {
                    if (result != null) {
                        mView.setFiveLotterResult(result)
                        // getPropsCardList(boxid, null)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }

    override fun duoChouLottery(boxid: String?, nums: Int) {
        ApiClient.homeApi.duoChouLottery(boxid ?: "", nums)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<FiveLotteryEntiy>() {
                override fun onSuccess(result: FiveLotteryEntiy?) {
                    if (result != null) {
                        mView.setDuoChouResult(result)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })

    }

    override fun popLottery(boxid: String?, discount: String?, nums: Int) {
        ApiClient.homeApi.popLottery(boxid ?: "", discount, nums)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<FiveLotteryEntiy>() {
                override fun onSuccess(result: FiveLotteryEntiy?) {
                    if (result != null) {
                        mView.setPopLotteryResult(result)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }

    override fun selectLottery(boxid: String?, nums: Int) {
        ApiClient.homeApi.selectLottery(boxid ?: "", nums)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<FiveLotteryEntiy>() {
                override fun onSuccess(result: FiveLotteryEntiy?) {
                    if (result != null) {
                        mView.setSelectLotteryResult(result)
//                        mView.setPropsCardList(null,result.card)
//                        getPropsCardList(boxid, result.card)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })

    }

    override fun selectLotteryActivity(boxId: String?, nums: String) {
        ApiClient.homeApi.selectLotteryActivity(boxId ?: "", nums)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<FiveLotteryEntiy>() {
                override fun onSuccess(result: FiveLotteryEntiy?) {
                    if (result != null) {
                        mView.setSelectLotteryActivityResult(result)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }


}