package com.dreamteam.timelapse.data

import android.util.Log
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

data class VideoDTO (
    val id: Int,
    val project_id: Int,
    val measurement_ids: String,
    val video_file: String?,
    val resolution:String,
    val duration: Int,
    val status: Int, //0 pas fini, 1 fini
    val name: String
){
    fun toVideo(): Video {
        fun parseIntArray(jsonString: String): List<Int> {
            val type = object : TypeToken<List<Int>>() {}.type
            try {
                Log.d("VideoDTO", Gson().fromJson<List<Int>>(jsonString, type).toString())
                return Gson().fromJson<List<Int>>(jsonString, type)
            }catch (e: Exception){
                Log.d("VideoDTO", jsonString)
                return Gson().fromJson<List<Int>>("[]", type)

                //throw Exception("Tentative de transformer une videoDTO en video alors que le format est pas bon")
            }
        }
        return Video(id, project_id, parseIntArray(measurement_ids), video_file, resolution, duration, status, name)
    }

}