package com.sunzones.data.repository

import com.sunzones.data.local.LocationDao
import com.sunzones.data.local.LocationEntity
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class LocationRepository @Inject constructor(
    private val locationDao: LocationDao
) {
    fun getAllLocations(): Flow<List<LocationEntity>> = locationDao.getAllLocations()

    suspend fun addLocation(location: LocationEntity): Long =
        locationDao.insertLocation(location)

    suspend fun deleteLocation(id: Long) = locationDao.deleteLocation(id)

    suspend fun getCount(): Int = locationDao.getCount()

    suspend fun replaceCurrentLocation(location: LocationEntity) {
        locationDao.deleteCurrentLocation()
        locationDao.insertLocation(location)
    }
}
