package com.example.pmulabs.room.repository

import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.example.pmulabs.room.dao.CommentDao
import com.example.pmulabs.room.models.Comment
import com.example.pmulabs.room.pagingSource.CommentPagingSource
import kotlinx.coroutines.flow.Flow

class OfflineCommentRepository(private val commentDao: CommentDao) : CommentRepository {
    override suspend fun insertComment(comment: Comment) = commentDao.insert(comment)
    override suspend fun updateComment(comment: Comment) = commentDao.update(comment)
    override suspend fun deleteComment(comment: Comment) = commentDao.delete(comment)
    override fun getAllComments(): Flow<List<Comment>> = commentDao.getAll()
    override fun getCountComment(idArticle : Int?) : Int = commentDao.getCountComment(idArticle)
    override fun getComments(): Flow<PagingData<Comment>> = Pager(config = PagingConfig(pageSize = 4, jumpThreshold = 4, initialLoadSize = 4) ){ CommentPagingSource(commentDao) }.flow

}