package com.yidianling.ydlcommon.custom.pay.redpacket.jump
import com.yidianling.ydlcommon.custom.data.YdlDataManager
import com.yidianling.ydlcommon.custom.http.RxUtils
import com.yidianling.ydlcommon.custom.http.ThrowableConsumer
import com.yidianling.ydlcommon.custom.mvp.RxPresenter
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers

/**
 * @author yuanwai
 * @描述:测评首页逻辑实现类
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/7/26
 */
class JumpPayPresenterImpl (view: IJumpPayContract.View) :
        RxPresenter<IJumpPayContract.View, IJumpPayContract.Model>(view),
    IJumpPayContract.Presenter {

    override fun createModel(): IJumpPayContract.Model {
        return JumpPayModelImpl()
    }

    /**
     * 请求红包列表
     */
    override fun requestCoupon() {
        YdlDataManager.getHttp().getCoupon()
                .subscribeOn(Schedulers.io())
                .compose(RxUtils.resultData())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(Consumer {
                    view.couponResult(it)
                }, object : ThrowableConsumer() {
                    override fun accept(msg: String) {
                        view.onFailed(msg)
                    }
                })
    }
}