package com.omixlab.lckcontrol.shared

import android.os.Parcel
import android.os.Parcelable

data class StreamPlan(
    val planId: String,
    val name: String,
    val status: String = "DRAFT",
    val destinations: List<StreamDestination> = emptyList(),
    val executionMode: String = "IN_GAME",
    val gameId: String = "",
) : Parcelable {

    constructor(parcel: Parcel) : this(
        planId = parcel.readString()!!,
        name = parcel.readString()!!,
        status = parcel.readString() ?: "DRAFT",
        destinations = parcel.createTypedArrayList(StreamDestination.CREATOR) ?: emptyList(),
        executionMode = if (parcel.dataAvail() > 0) parcel.readString() ?: "IN_GAME" else "IN_GAME",
        gameId = if (parcel.dataAvail() > 0) parcel.readString() ?: "" else "",
    )

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(planId)
        parcel.writeString(name)
        parcel.writeString(status)
        parcel.writeTypedList(destinations)
        parcel.writeString(executionMode)
        parcel.writeString(gameId)
    }

    override fun describeContents(): Int = 0

    companion object CREATOR : Parcelable.Creator<StreamPlan> {
        override fun createFromParcel(parcel: Parcel) = StreamPlan(parcel)
        override fun newArray(size: Int) = arrayOfNulls<StreamPlan>(size)
    }
}
