package com.sheep.gamegroup.presenter;

import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.util.SheepSubscriber;
import com.sheep.jiuyan.samllsheep.SheepApp;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by ljy on 2018/3/21.
 */

public class WithdrawalListPresenter implements WithdrawalListContract.Presenter {

    private WithdrawalListContract.View view;
    private ApiService apiService;

    @Inject
    public WithdrawalListPresenter(WithdrawalListContract.View view, ApiService apiService) {
        this.view = view;
        this.apiService = apiService;
    }

    @Override
    public void goWithdrawal(int page, int per_page, String start_time, String end_time) {

        apiService.goWithdrawal(page, per_page, start_time, end_time)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.failView(baseMessage);
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        view.updataView(baseMessage);
                    }
                });
    }
}
