package com.ponzischeme89.memby.ui

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

class MediaBadgesTest {
    @Test
    fun `derives premium video and audio badges without duplicates`() {
        val item = BaseItem(
            id = "movie",
            mediaStreams = listOf(
                MediaStream(
                    type = "Video",
                    codec = "hevc",
                    width = 3840,
                    videoRangeType = "DOVI",
                    title = "Dolby Vision HEVC",
                ),
                MediaStream(type = "Audio", title = "TrueHD Dolby Atmos"),
            ),
        )

        assertEquals(
            listOf("4K", "DOLBY VISION", "HEVC", "DOLBY ATMOS"),
            mediaBadges(item),
        )
    }

    /** HDR10+ used to be named in the spec row and collapse to a plain "HDR" badge. */
    @Test
    fun `names HDR10+ rather than collapsing it to HDR`() {
        val item = BaseItem(
            id = "movie",
            mediaStreams = listOf(
                MediaStream(type = "Video", width = 3840, videoRangeType = "HDR10+"),
            ),
        )

        assertEquals(listOf("4K", "HDR10+"), mediaBadges(item))
    }

    /**
     * The badge and the spec row's `(4K)` suffix used to disagree — 3800 against 3400 —
     * so a 3600-wide file was 4K on the detail page and not on the card.
     */
    @Test
    fun `uses the same 4K threshold as the technical spec row`() {
        fun badgesAt(width: Int) = mediaBadges(
            BaseItem(id = "m", mediaStreams = listOf(MediaStream(type = "Video", width = width))),
        )

        assertEquals(emptyList<String>(), badgesAt(3_600))
        assertEquals(listOf("4K"), badgesAt(3_840))
    }

    @Test
    fun `returns no badges when stream metadata is unavailable`() {
        assertEquals(emptyList<String>(), mediaBadges(BaseItem(id = "unknown")))
    }
}
