package com.fusi24.rfid.base;

import androidx.appcompat.app.AppCompatActivity;

import com.fusi24.rfid.config.Constant;
import com.fusi24.rfid.data.DataManager;
import com.fusi24.rfid.data.api.RestService;
import com.fusi24.rfid.data.api.RestServiceFactory;

import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public abstract class BaseActivity extends AppCompatActivity {

    private RestService restService;
    private DataManager manager;

    public RestService getRestService() {
        if (restService == null) {
            restService = RestServiceFactory.create(getJwtToken());
        }
        return restService;
    }

    public DataManager getManager() {
        if (manager == null) {
            manager = new DataManager(getRestService());
        }
        return manager;
    }

    protected Scheduler getAndroidScheduler() {
        return AndroidSchedulers.mainThread();
    }

    protected Scheduler getProcessScheduler() {
        return Schedulers.io();
    }

    private String getJwtToken() {
        return Constant.JWT_TOKEN;
    }

}
