package com.example.lexilearn.data.repository

import android.content.Context
import com.example.lexilearn.data.local.SharedPrefHelper
import com.example.lexilearn.data.remote.FirebaseHelper
import com.example.lexilearn.data.model.MaterialDataModel


class MaterialRepository(private val context: Context) {
    private val sharedPrefHelper = SharedPrefHelper(context)
    private val firebaseHelper = FirebaseHelper(context)

    fun getMaterialData(callback: (List<MaterialDataModel>) -> Unit) {
        val cachedData = sharedPrefHelper.getMaterialList()
        if (cachedData != null) {
            callback(cachedData)
        } else {
            firebaseHelper.fetchMaterials { materials ->
                callback(materials)
            }
        }
    }
}