package com.example.petstoremobile.repositories;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.example.petstoremobile.utils.Resource;
import com.example.petstoremobile.utils.RetrofitUtils;

import retrofit2.Call;

/**
 * Base class for all repositories to provide common functionality for API calls.
 */
public abstract class BaseRepository {
    protected final String TAG;

    protected BaseRepository(String tag) {
        this.TAG = tag;
    }

    /**
     * Executes a Retrofit call and returns a LiveData containing the Resource.
     */
    protected <T> LiveData<Resource<T>> executeCall(Call<T> call) {
        MutableLiveData<Resource<T>> data = new MutableLiveData<>();
        RetrofitUtils.enqueue(call, data, TAG);
        return data;
    }
}
