package com.ponzischeme89.memby.ui

import com.ponzischeme89.memby.data.model.BaseItem
import com.ponzischeme89.memby.data.model.UserItemData
import com.ponzischeme89.memby.ui.detail.primaryActionLabel
import org.junit.Assert.assertEquals
import org.junit.Test

class PrimaryActionLabelTest {
    @Test
    fun `watched movie can be rewatched`() {
        val movie = BaseItem(
            id = "movie",
            name = "Movie",
            type = "Movie",
            userData = UserItemData(played = true),
        )

        assertEquals("Rewatch", primaryActionLabel(movie))
    }

    @Test
    fun `part watched movie still resumes`() {
        val movie = BaseItem(
            id = "movie",
            name = "Movie",
            type = "Movie",
            userData = UserItemData(played = true, playbackPositionTicks = 1),
        )

        assertEquals("Resume", primaryActionLabel(movie))
    }

    @Test
    fun `unwatched movie still plays`() {
        val movie = BaseItem(id = "movie", name = "Movie", type = "Movie")

        assertEquals("Play", primaryActionLabel(movie))
    }

    /** The episode page is reached from Continue Watching; the button confirms which one. */
    @Test
    fun `an episode names itself on the button`() {
        assertEquals("Play S04E04", primaryActionLabel(episode(4, 4)))
    }

    @Test
    fun `a part watched episode resumes by name`() {
        val resuming = episode(4, 4).copy(userData = UserItemData(playbackPositionTicks = 1))

        assertEquals("Resume S04E04", primaryActionLabel(resuming))
    }

    /** A series' button names its next episode in the same form the episode page uses. */
    @Test
    fun `a series names its next episode`() {
        val series = BaseItem(id = "series", name = "Series", type = "Series")

        assertEquals("Play S01E02", primaryActionLabel(series, episode(1, 2)))
    }

    @Test
    fun `an unnumbered episode falls back to a bare verb`() {
        val unnumbered = BaseItem(id = "e", name = "Pilot", type = "Episode")

        assertEquals("Play", primaryActionLabel(unnumbered))
    }

    private fun episode(season: Int, number: Int) = BaseItem(
        id = "s${season}e$number",
        name = "Episode $number",
        type = "Episode",
        parentIndexNumber = season,
        indexNumber = number,
    )
}
