package com.dreamteam.timelapse.data

import android.os.Parcel
import android.os.Parcelable
import android.util.Log
import com.dreamteam.timelapse.R
import java.util.Date

//{
//    "id": 1,
//    "creation": "2024-10-24T13:46:04.513Z",
//    "status": "test",
//    "description": "Projet de Test",
//    "titre": "Test Project"
//}
data class Project(
    val id: Int,
    val name: String,
    val description: String,
    val start_date: Date,
    val status: Int,
    //val thumbnail_url: String?
)  : Parcelable {

    fun getStatusText(): String{
        Log.i("Project", "Status $status being trasnlated")
        val statusArr = arrayOf("Brouillon", "En Cours", "Terminé", "En cours d'arret")
        return statusArr[status]
    }
    fun getStatusColor(): Int{
        return when (status) {
            0 -> R.color.brouillon
            1 -> R.color.en_cours
            2 -> R.color.termine
            3 -> R.color.annule
            else -> R.color.default_badge
        }
    }

    // Constructor to recreate from Parcel
    constructor(parcel: Parcel) : this(
        parcel.readInt(),
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        Date(parcel.readLong()),
        parcel.readInt(),
        //parcel.readString()
        )

    // Write object to Parcel
    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(id)
        parcel.writeString(name)
        parcel.writeString(description)
        parcel.writeLong(start_date.time)
        parcel.writeInt(status)
    }

    // Describe the contents of the Parcel
    override fun describeContents(): Int = 0

    companion object CREATOR : Parcelable.Creator<Project> {
        override fun createFromParcel(parcel: Parcel): Project {
            return Project(parcel)
        }

        override fun newArray(size: Int): Array<Project?> {
            return arrayOfNulls(size)
        }
    }
//    fun getThumbnail(): String {
//        return images[0]
//    }
}
