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 SignCardPresenter implements SignCardContract.Presenter {

    private SignCardContract.View view;
    private ApiService apiService;

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


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

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

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

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

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

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

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

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

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

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

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

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

}
