// SPDX-FileCopyrightText: Adam Evyčędo
//
// SPDX-License-Identifier: GPL-3.0-or-later
package xyz.apiote.bimba.czwek.journeys

import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import xyz.apiote.bimba.czwek.repo.Journey
import xyz.apiote.bimba.czwek.repo.Place

class JourneysViewModel : ViewModel() {

	private val _journeys = MutableLiveData<List<Journey>>()
	val journeys: LiveData<List<Journey>> = _journeys

	fun getJourneys(context: Context, origin: Place, destination: Place) {
		viewModelScope.launch {
			Log.i("Journeys", "getting journeys")
			_journeys.value = xyz.apiote.bimba.czwek.api.getJourney(origin, destination, context)
			Log.i("Journeys", "got ${journeys.value?.size} journeys")

			journeys.value?.forEach {
				Log.i("Journeys", "$it")
			}
		}

	}
}