package com.ym.game.presenter

import com.ym.game.contract.TurntableContract
import com.ym.library.module.TurntableEntity
import com.ym.library.net.BaseObserver
import com.ym.library.net.GameApiClient
import com.ym.library.net.RxSchedulers


/**
 *Craeted by ${junqi.li}
 *Craeted by 2020/9/11
 */
class TurntablePresenter : TurntableContract.Presenter {
    var mView: TurntableContract.View

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

    /**
     * 转盘列表
     */
    override fun getTurntableList() {
        GameApiClient.gameApi.getTurntableList().compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<TurntableEntity>() {
            override fun onSuccess(result: TurntableEntity?) {
                if (result != null) {
                    mView?.turntableListResult(result)
                }
            }

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

    /**
     * 转盘抽奖结果
     */
    override fun getTurntableLotteryResult() {
        GameApiClient.gameApi.getLotteryResult().compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<TurntableEntity.Turntable>() {
            override fun onSuccess(result: TurntableEntity.Turntable?) {
                if (result != null) {
                    mView?.turntableLotteryResult(result)
                }
            }

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