package de.krisenvorrat.app.data.repository

import de.krisenvorrat.app.data.db.dao.CategoryDao
import de.krisenvorrat.app.data.db.entity.CategoryEntity
import de.krisenvorrat.app.domain.repository.CategoryRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import javax.inject.Inject

internal class CategoryRepositoryImpl @Inject constructor(
    private val dao: CategoryDao
) : CategoryRepository {

    override fun getAll(): Flow<List<CategoryEntity>> = dao.getAll()

    override suspend fun insert(category: CategoryEntity) =
        withContext(Dispatchers.IO) { dao.insert(category) }

    override suspend fun update(category: CategoryEntity) =
        withContext(Dispatchers.IO) { dao.update(category) }

    override suspend fun delete(category: CategoryEntity) =
        withContext(Dispatchers.IO) { dao.delete(category) }
}
