package com.radiola.domain.usecase

import com.radiola.domain.model.Station
import com.radiola.domain.repository.FavoritesRepository
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test

class ToggleFavoriteUseCaseTest {

    private val favoritesRepository: FavoritesRepository = mockk(relaxed = true)
    private val useCase = ToggleFavoriteUseCase(favoritesRepository)

    @Test
    fun `invoke adds favorite when not favorite`() = runTest {
        val station = Station(1, "Record", "rr", "", "", "", emptyList(), 0)
        coEvery { favoritesRepository.isFavorite(station.id) } returns flowOf(false)

        useCase(station)

        coVerify { favoritesRepository.addFavorite(station) }
    }

    @Test
    fun `invoke removes favorite when already favorite`() = runTest {
        val station = Station(1, "Record", "rr", "", "", "", emptyList(), 0)
        coEvery { favoritesRepository.isFavorite(station.id) } returns flowOf(true)

        useCase(station)

        coVerify { favoritesRepository.removeFavorite(station.id) }
    }
}
