package com.tencent.liteav.demo.superplayer.player

import com.android.cast.dlna.core.ICast
import com.android.cast.dlna.core.ICast.ICastImage
import com.android.cast.dlna.core.ICast.ICastVideo

object CastObject {
    fun newInstance(url: String, id: String, name: String): ICast {
        return if (url.endsWith(".mp4") || url.endsWith(".m3u8")) {
            CastVideo(url, id, name)
        } else if (url.endsWith(".jpg")) {
            CastImage(url, id, name)
        } else {
            throw IllegalArgumentException("please check cast object type.")
        }
    }
}

data class CastImage(
    private val url: String,
    private val id: String,
    private val name: String,
    private val size: Long = 0L
) : ICastImage {

    override fun getId(): String = id
    override fun getUri(): String = url
    override fun getName(): String = name
    override fun getSize(): Long = size
}

data class CastVideo(
    private val url: String,
    private val id: String,
    private val name: String,
    private val size: Long = 0L,
    private val bitrate: Long = 0
) : ICastVideo {

    var duration: Long = 0

    override fun getId(): String = id
    override fun getUri(): String = url
    override fun getName(): String = name
    override fun getDurationMillSeconds(): Long = duration
    override fun getSize(): Long = size
    override fun getBitrate(): Long = bitrate
}