package com.example.dtf.repositories.offline

import androidx.paging.*
import com.example.dtf.dao.PostDao
import com.example.dtf.models.Post
import com.example.dtf.repositories.IPostRepository
import javax.inject.Inject

class OfflinePostRepository @Inject constructor(
    private val postDao: PostDao
) : IPostRepository {
    override suspend fun insert(post: Post) = postDao.insert(post)

    override suspend fun update(post: Post) = postDao.update(post)

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

    override fun getByCategory(categoryId: Int) = Pager(
        PagingConfig(
            pageSize = 3,
            enablePlaceholders = false
        ),
        pagingSourceFactory = { postDao.getByCategory(categoryId.toString()) }
    ).flow
}