package com.omixlab.lckcontrol.shared

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

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

    constructor(parcel: Parcel) : this(
        name = parcel.readString()!!,
        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(name)
        parcel.writeTypedList(destinations)
        parcel.writeString(executionMode)
        parcel.writeString(gameId)
    }

    override fun describeContents(): Int = 0

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