package mx.trackermap.TrackerMap.controllers import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import mx.trackermap.TrackerMap.client.apis.GeofencesApi import mx.trackermap.TrackerMap.client.models.Geofence @DelicateCoroutinesApi class GeofencesController( private val geofencesApi: GeofencesApi ) { val geofencesFlow = MutableStateFlow>(emptyMap()) init { GlobalScope.launch { fetchGeofences() } } private suspend fun fetchGeofences() { val geofences = geofencesApi.geofencesGet(all = true) val geofencesMap = mutableMapOf() geofences.forEach { geofencesMap[it.id!!] = it } geofencesFlow.value = geofencesMap } }