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/18.
 */

public class SignRankingsPresenter implements SignRankingsContract.Presenter {

    private SignRankingsContract.View view;
    private ApiService apiService;

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



    @Override
    public void getContinuePunchTop() {
        apiService.getContinuePunchTop()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        try {
                            view.failPunch(baseMessage);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        try {
                            view.succPunch(baseMessage);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    @Override
    public void getTotalPunchTop() {
        apiService.getTotalPunchTop()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        try {
                            view.failPunch(baseMessage);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        try {
                            view.succPunch(baseMessage);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

}
