package de.krisenvorrat.app.data.db.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import androidx.room.Upsert
import de.krisenvorrat.app.data.db.entity.LocationEntity
import kotlinx.coroutines.flow.Flow

@Dao
internal interface LocationDao {

    @Insert
    suspend fun insert(location: LocationEntity)

    @Update
    suspend fun update(location: LocationEntity)

    @Delete
    suspend fun delete(location: LocationEntity)

    @Query("SELECT * FROM locations")
    fun getAll(): Flow<List<LocationEntity>>

    @Query("SELECT * FROM locations WHERE id = :id")
    suspend fun getById(id: Int): LocationEntity?

    @Upsert
    suspend fun upsertAll(locations: List<LocationEntity>)
}
