package de.krisenvorrat.app.domain.usecase

import de.krisenvorrat.app.data.db.entity.CategoryEntity
import de.krisenvorrat.app.data.db.entity.LocationEntity
import de.krisenvorrat.app.domain.repository.CategoryRepository
import de.krisenvorrat.app.domain.repository.LocationRepository
import kotlinx.coroutines.flow.first
import javax.inject.Inject

internal class SeedDatabaseUseCase @Inject constructor(
    private val categoryRepository: CategoryRepository,
    private val locationRepository: LocationRepository
) {

    suspend operator fun invoke() {
        if (categoryRepository.getAll().first().isEmpty()) {
            listOf(
                "Lebensmittel",
                "Wasser",
                "Medikamente",
                "Ausrüstung",
                "Hygiene",
                "Energie & Licht",
                "Dokumente"
            ).forEach { name ->
                categoryRepository.insert(CategoryEntity(name = name))
            }
        }

        if (locationRepository.getAll().first().isEmpty()) {
            locationRepository.insert(LocationEntity(name = "Keller"))
        }
    }
}
