package com.ym.modulecommon.news.presenter

import com.ym.modulecommon.module.WithdrawResultEntity
import com.ym.modulecommon.net.BaseObserver
import com.ym.modulecommon.net.RxSchedulers
import com.ym.modulecommon.net.ZXADClient
import com.ym.modulecommon.net.ZXNewsClient
import com.ym.modulecommon.news.entity.AdNewsHomeEntity
import com.ym.modulecommon.news.contract.AdNewsHomeContract

class AdNewsHomePresenter: AdNewsHomeContract.Presenter {

    private var mView:AdNewsHomeContract.View

    constructor(mView: AdNewsHomeContract.View) {
        this.mView = mView
        getHomeData()
    }

    override fun getHomeData() {
        ZXNewsClient.adApi.getNewsHomeData().compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<AdNewsHomeEntity>() {
                override fun onSuccess(result: AdNewsHomeEntity) {
                    mView.homeDataResult(result)
                }

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

    override fun getDoWd() {
        ZXNewsClient.adApi.getReward().compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<WithdrawResultEntity>() {
                override fun onSuccess(result: WithdrawResultEntity) {
                    mView.withdrawResult(result)
                }

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