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.cms.net.model.chat.HasWinterBoxEntity
import com.zxhl.cms.net.model.chat.RoomTypeEntity
import com.zxhl.main.page.contract.VoiceRoomContract

class VoiceRoomPrsenter:VoiceRoomContract.Presenter {
    private val mView: VoiceRoomContract.View


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

    override fun getTab() {
        ApiClient.chatApi.getTab().compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<List<RoomTypeEntity>>() {
                override fun onSuccess(result: List<RoomTypeEntity>?) {
                        mView.setTab(result)
                }

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

                }
            })
    }

    override fun hasWinterBox() {
        ApiClient.chatApi.hasWinterBox().compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<HasWinterBoxEntity>() {
                override fun onSuccess(result: HasWinterBoxEntity?) {
                    if(result!=null){
                        mView.showWinterBox(result.has)
                    }

                }

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

                }
            })
    }

    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?) {

                }

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

                }
            })
    }
}