package com.zxhl.main.page.presenter

import android.util.Log
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.chat.BoxRewardEntity
import com.zxhl.main.page.contract.WinterBoxContract

class WinterBoxPresenter:WinterBoxContract.Presenter {
    private val mView: WinterBoxContract.View


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

    override fun getWinterBox() {
        ApiClient.chatApi.getWinterBox().compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<Any>() {
                override fun onSuccess(result: Any?) {

                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    Log.e("MXL", "ERROR" + code + errorMsg)

                }
            })
    }

    override fun openWinterBox() {
        ApiClient.chatApi.openWinterBox().compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<BoxRewardEntity>() {
                override fun onSuccess(result: BoxRewardEntity?) {
                    mView.getReward(result?.info?.reward)
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    Log.e("MXL", "ERROR" + code + errorMsg)

                }
            })
    }
}