package com.ponzischeme89.memby.ui

import com.ponzischeme89.memby.data.launchResumePositionMs
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 ContinueWatchingResumeTest {
    @Test
    fun `detail metadata keeps the continue watching playhead and resume label`() {
        val card = BaseItem(
            id = "episode",
            name = "The Episode",
            type = "Episode",
            indexNumber = 3,
            parentIndexNumber = 1,
            userData = UserItemData(playbackPositionTicks = 36_000_000L),
        )
        val detailsWithoutUserData = card.copy(
            overview = "The richer record fetched after focus.",
            userData = null,
        )

        val focused = focusedItemWithMetadata(card, detailsWithoutUserData)

        assertEquals(36_000_000L, focused.userData?.playbackPositionTicks)
        assertEquals("Resume S01E03", primaryActionLabel(focused))
        assertEquals("The richer record fetched after focus.", focused.overview)
    }

    @Test
    fun `pressed card resume point outranks a prefetched zero`() {
        assertEquals(
            36_000L,
            launchResumePositionMs(resolvedPositionMs = 0L, requestedPositionMs = 36_000L),
        )
        assertEquals(
            42_000L,
            launchResumePositionMs(resolvedPositionMs = 42_000L, requestedPositionMs = 0L),
        )
    }
}
