package com.adealink.weparty.module.image.data

import android.os.Parcelable
import com.adealink.frame.mvvm.livedata.ExtMutableLiveData
import kotlinx.parcelize.Parcelize

@Parcelize
data class VideoItem(val url: String, val width: Int? = null, val height: Int? = null) : Parcelable

data class MediaUpload(
    val startLD: ExtMutableLiveData<Unit> = ExtMutableLiveData(),
    val endLD: ExtMutableLiveData<Unit> = ExtMutableLiveData(),
    val progressLD: ExtMutableLiveData<Pair<Long, Long>> = ExtMutableLiveData() //progress, total
)

sealed class MediaData(
    //远端路径
    var url: String?,

    //本地路径
    val path: String?,
    val uri: String?
) {

    val mediaUpload = MediaUpload()

    var width: Int? = null
    var height: Int? = null

    fun isRemote(): Boolean {
        return !url.isNullOrEmpty()
    }

    fun isLocal(): Boolean {
        return !uri.isNullOrEmpty()
    }

    fun isNull(): Boolean {
        return url.isNullOrEmpty() && path.isNullOrEmpty() && uri.isNullOrEmpty()
    }
}

class PhotoData(
    url: String?,
    path: String?,
    uri: String?
) : MediaData(url, path, uri) {

}

fun PhotoData?.sameWith(other: PhotoData?): Boolean {
    if (this == null && other == null) {
        return true
    }
    return this?.url == other?.url
            && this?.path == other?.path
            && this?.uri == other?.uri
}

class VideoData(
    url: String?,
    path: String?,
    uri: String?
) : MediaData(url, path, uri) {

    //视频封面
    var cover: PhotoData? = null
}

fun VideoData?.sameWith(other: VideoData?): Boolean {
    if (this == null && other == null) {
        return true
    }
    return this?.url == other?.url
            && this?.path == other?.path
            && this?.uri == other?.uri
}