package com.example.pmulabs.room.repository

import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.example.pmulabs.room.dao.TagDao
import com.example.pmulabs.room.models.Tag
import com.example.pmulabs.room.pagingSource.TagPagingSource
import kotlinx.coroutines.flow.Flow

class OfflineTagRepository(private val tagDao: TagDao) : TagRepository {
    override suspend fun insertTag(tag: Tag) = tagDao.insert(tag)
    override suspend fun updateTag(tag: Tag) = tagDao.update(tag)
    override suspend fun deleteTag(tag: Tag) = tagDao.delete(tag)
    override fun getAllTags(): Flow<List<Tag>> = tagDao.getAll()
    override fun getTagById(idTag: Int): Flow<Tag> = tagDao.getTagById(idTag)
    override fun getTagByName(nameTag: String): Flow<Tag> = tagDao.getTagByName(nameTag)
    override fun getTags(): Flow<PagingData<Tag>> = Pager(config = PagingConfig(pageSize = 4, jumpThreshold = 4, initialLoadSize = 4) ){ TagPagingSource(tagDao) }.flow

}