package com.example.dtf.repositories.offline

import androidx.paging.Pager
import androidx.paging.PagingConfig
import com.example.dtf.dao.CategoryDao
import com.example.dtf.models.Category
import com.example.dtf.repositories.ICategoryRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class OfflineCategoryRepository @Inject constructor(
    private val categoryDao: CategoryDao
) : ICategoryRepository {

    override fun getAll() = Pager(
        PagingConfig(
            pageSize = 5,
            enablePlaceholders = false
        ),
        pagingSourceFactory = { categoryDao.getAll() }
    ).flow

    override fun getAllCached(): Flow<List<Category>> {
        return categoryDao.getAllCached()
    }

    override fun getFirst(): Flow<Category?> {
        return categoryDao.getFirst()
    }
}