package de.krisenvorrat.app.data.repository

import de.krisenvorrat.app.data.db.dao.LocationDao
import de.krisenvorrat.app.data.db.entity.LocationEntity
import de.krisenvorrat.app.domain.repository.LocationRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import javax.inject.Inject

internal class LocationRepositoryImpl @Inject constructor(
    private val dao: LocationDao
) : LocationRepository {

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

    override suspend fun insert(location: LocationEntity) =
        withContext(Dispatchers.IO) { dao.insert(location) }

    override suspend fun update(location: LocationEntity) =
        withContext(Dispatchers.IO) { dao.update(location) }

    override suspend fun delete(location: LocationEntity) =
        withContext(Dispatchers.IO) { dao.delete(location) }
}
