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 SignRecordPresenter implements SignRecordContract.Presenter {

    private SignRecordContract.View view;
    private ApiService apiService;

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

    @Override
    public void getStatistics() {
        apiService.getStatistics()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.failStatistics(baseMessage);
                    }

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

    @Override
    public void getPunchLog(final int action) {
        apiService.getPunchLog(action)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.failPunchLog(baseMessage);
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        view.succPunchLog(baseMessage,action);
                    }
                });
    }

}
