package com.ponzischeme89.memby.data

import com.ponzischeme89.memby.data.model.MediaSourceInfo
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class PlaybackDeliveryTest {
    @Test
    fun directPlayUsesOriginalOnlyWhenServerMarksItSupported() {
        val delivery = selectPlaybackDelivery(
            MediaSourceInfo(
                supportsDirectPlay = true,
                directStreamUrl = "/Videos/item/stream.mkv",
                transcodingUrl = "/Videos/item/master.m3u8",
            ),
        )

        assertNull(delivery.url)
        assertEquals("DirectPlay", delivery.playMethod)
    }

    @Test
    fun negotiatedDirectStreamIsUsedForContainerCompatibility() {
        val delivery = selectPlaybackDelivery(
            MediaSourceInfo(
                supportsDirectPlay = false,
                supportsDirectStream = true,
                directStreamUrl = "/Videos/item/stream.mp4",
                transcodingUrl = "/Videos/item/master.m3u8",
            ),
        )

        assertEquals("/Videos/item/stream.mp4", delivery.url)
        assertEquals("DirectStream", delivery.playMethod)
    }

    @Test
    fun forcedFallbackUsesTranscodeEvenWhenDirectPlayWasAdvertised() {
        val delivery = selectPlaybackDelivery(
            MediaSourceInfo(
                supportsDirectPlay = true,
                transcodingUrl = "/Videos/item/master.m3u8",
            ),
            forceTranscode = true,
        )

        assertEquals("/Videos/item/master.m3u8", delivery.url)
        assertEquals("Transcode", delivery.playMethod)
    }
}
