package com.fusi24.rfid.ui.scanresult;

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

import io.reactivex.Scheduler;

public class ScanResultPresenter extends BasePresenter<ScanResultView> {

    private DataManager manager;

    private Scheduler androidScheduler;
    private Scheduler processScheduler;

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

    void checkRfidCard(String numberRfid, Integer permitId, String[] expand) {
        disposable.add(manager.checkRfidCard(numberRfid, permitId, expand)
                .observeOn(androidScheduler)
                .subscribeOn(processScheduler)
                .subscribe(dataRfid -> {
                    if (isViewAttached()) {
                        getView().showDataRfid(dataRfid);
                    }
                }, throwable -> {
                    if (isViewAttached()) {
                        getView().showError(throwable);
                    }
                }));
    }

}
