package ru.fincode.tsudesk.feature.news.data

import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import kotlinx.coroutines.flow.Flow
import ru.fincode.tsudesk.feature.news.data.datasource.NewsArchiveDataSource
import ru.fincode.tsudesk.feature.news.data.paging.NewsArchivePagingSource
import ru.fincode.tsudesk.feature.news.domain.model.NewsItem
import ru.fincode.tsudesk.feature.news.domain.repository.NewsRepository
import javax.inject.Inject

class NewsRepositoryImpl @Inject constructor(
    private val dataSource: NewsArchiveDataSource
) : NewsRepository {

    override fun paging(): Flow<PagingData<NewsItem>> =
        Pager(
            config = PagingConfig(
                pageSize = 20,
                initialLoadSize = 20,
                prefetchDistance = 2,
                enablePlaceholders = false
            ),
            pagingSourceFactory = { NewsArchivePagingSource(dataSource) }
        ).flow
}