package com.ponzischeme89.memby.ui.genre

import com.ponzischeme89.memby.data.model.BaseItem
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class GenreBrowseTest {
    @Test
    fun `whole library tab names match each destination`() {
        assertEquals("All Movies", allMediaLabel("Movie"))
        assertEquals("All TV shows", allMediaLabel("Series"))
    }

    @Test
    fun `genre tabs have a stable product order`() {
        assertEquals(
            listOf(
                "All Movies",
                "Action & Adventure",
                "Comedy",
                "Crime",
                "Drama",
                "Horror",
                "Mystery",
                "Sci-Fi & Fantasy",
                "Thriller",
                "War & History",
            ),
            genreCategoryTabs("Movie").take(10).map(GenreCategory::label),
        )
    }

    @Test
    fun `neighbouring raw genres merge into one Emby filter`() {
        assertEquals("Action|Adventure", genreCategory("Movie", "action-adventure").filter)
        assertEquals(
            "Science Fiction|Sci-Fi|Sci Fi|Fantasy",
            genreCategory("Series", "sci-fi-fantasy").filter,
        )
        assertEquals("War|History", genreCategory("Movie", "war-history").filter)
    }

    @Test
    fun `series keeps the same core tabs and adds reality`() {
        assertEquals(
            genreCategories("Movie").map(GenreCategory::id),
            genreCategories("Series").dropLast(1).map(GenreCategory::id),
        )
        assertEquals("reality", genreCategories("Series").last().id)
    }

    @Test
    fun `favourite overrides update a paged card copy immediately`() {
        val item = BaseItem(id = "film", name = "Film", type = "Movie")
        assertFalse(item.isFavorite)
        assertTrue(item.withFavourite(true).isFavorite)
        assertFalse(item.withFavourite(true).withFavourite(false).isFavorite)
    }

    @Test
    fun `watched overrides update a paged poster immediately`() {
        val item = BaseItem(id = "film", name = "Film", type = "Movie")
        assertFalse(item.userData?.played == true)
        assertTrue(item.withPlayed(true).userData?.played == true)
        assertFalse(item.withPlayed(true).withPlayed(false).userData?.played == true)
    }
}
