package com.radiola.domain.usecase

import com.radiola.domain.model.Station
import com.radiola.domain.repository.FavoritesRepository
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class ToggleFavoriteUseCase @Inject constructor(
    private val favoritesRepository: FavoritesRepository
) {
    suspend operator fun invoke(station: Station) {
        val isFav = favoritesRepository.isFavorite(station.id).first()
        if (isFav) {
            favoritesRepository.removeFavorite(station.id)
        } else {
            favoritesRepository.addFavorite(station)
        }
    }
}
