package com.fusi24.rfid.ui.login;

import com.fusi24.rfid.base.BasePresenter;
import com.fusi24.rfid.data.DataManager;
import com.fusi24.rfid.data.entity.DataAuth;

import io.reactivex.Scheduler;

class LoginPresenter extends BasePresenter<LoginView> {

    private DataManager manager;

    private Scheduler androidScheduler;
    private Scheduler processScheduler;

    LoginPresenter(DataManager manager, Scheduler androidScheduler, Scheduler processScheduler) {
        this.manager = manager;
        this.androidScheduler = androidScheduler;
        this.processScheduler = processScheduler;
    }

    void userLogin(DataAuth dataAuth) {
        disposable.add(manager.userLogin(dataAuth)
                .observeOn(androidScheduler)
                .subscribeOn(processScheduler)
                .subscribe(result -> {
                    if (isViewAttached()) {
                        getView().showLoginSuccess(result);
                    }
                }, throwable -> {
                    if (isViewAttached()) {
                        getView().showError(throwable);
                    }
                }));
    }

}
