package com.example.dtf.repositories.offline

import androidx.paging.*
import com.example.dtf.dao.CommentDao
import com.example.dtf.models.Comment
import com.example.dtf.repositories.ICommentRepository
import javax.inject.Inject

class OfflineCommentRepository @Inject constructor(
    private val commentDao: CommentDao
) : ICommentRepository {
    override suspend fun insert(comment: Comment) = commentDao.insert(comment)

    override fun getById(id: Int) = commentDao.getById(id)

    override fun getByPost(postId: Int) = Pager(
        PagingConfig(
            pageSize = 5,
            enablePlaceholders = false
        ),
        pagingSourceFactory = { commentDao.getByPost(postId) }
    ).flow
}