package net.schueller.peertube.feature_video.data.remote.dto

import net.schueller.peertube.feature_video.domain.model.Video
import java.util.Date

data class VideoDto(
    val account: AccountDto?,
    val blacklisted:  Boolean?,
    val blacklistedReason: String?,
    val category: CategoryDto?,
    val channel: ChannelDto?,
    val commentsEnabled:  Boolean,
    val createdAt: Date?,
    val description: String?,
    val descriptionPath: String?,
    val dislikes: Int,
    val downloadEnabled:  Boolean,
    val duration: Int,
    val embedPath: String?,
    val files: List<FileDto>?,
    val id: Int,
    val isLive:  Boolean,
    val isLocal:  Boolean,
    val language: LanguageDto?,
    val licence: LicenceDto?,
    val likes: Int,
    val name: String?,
    val nsfw: Boolean,
    val originallyPublishedAt: Date?,
    val previewPath: String?,
    val privacy: PrivacyDto?,
    val publishedAt: Date?,
    val scheduledUpdate: ScheduledUpdateDto?,
    val shortUUID: String?,
    val state: StateDto?,
    val streamingPlaylists: List<SteamingPlaylistDto>?,
    val support: String?,
    val tags: List<String>?,
    val thumbnailPath: String?,
    val trackerUrls: List<String>?,
    val updatedAt: Date?,
    val userHistory: UserHistoryDto?,
    val uuid: String,
    val viewers: Int,
    val views: Int,
    val waitTranscoding:  Boolean?,

)

fun VideoDto.toVideo(): Video {
    return Video(
        account = account?.toAccount(),
        blacklisted = blacklisted,
        blacklistedReason = blacklistedReason,
        category = category?.toCategory(),
        channel = channel?.toChannel(),
        commentsEnabled = commentsEnabled,
        createdAt = createdAt,
        description = description,
        descriptionPath = descriptionPath,
        dislikes = dislikes,
        downloadEnabled = downloadEnabled,
        duration = duration,
        embedPath = embedPath,
        files = files?.map{ it.toFile() },
        id = id,
        isLive = isLive,
        isLocal = isLocal,
        language = language?.toLanguage(),
        licence = licence?.toLicence(),
        likes = likes,
        name = name,
        nsfw = nsfw,
        originallyPublishedAt = originallyPublishedAt,
        previewPath = previewPath,
        privacy = privacy?.toPrivacy(),
        publishedAt = publishedAt,
        scheduledUpdate = scheduledUpdate?.toScheduledUpdate(),
        shortUUID = shortUUID,
        state = state?.toState(),
        streamingPlaylists = streamingPlaylists?.map { it.toSteamingPlaylist() },
        support = support,
        tags = tags,
        thumbnailPath = thumbnailPath,
        trackerUrls = trackerUrls,
        updatedAt = updatedAt,
        userHistory = userHistory?.toUserHistory(),
        uuid = uuid,
        views = views,
        waitTranscoding = waitTranscoding
    )
}