package com.obdwidgets.model

import android.graphics.Color
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

/**
 * Konfiguration für ein Widget
 */
@Parcelize
@Serializable
data class WidgetConfig(
    val widgetId: Int,
    val widgetType: String,
    val parameter: String,
    val minValue: Float,
    val maxValue: Float,
    val customLabel: String? = null,
    val labelColor: Int = Color.LTGRAY,
    val valueColor: Int = Color.WHITE,
    val needleColor: Int = Color.RED,
    val scaleColor: Int = Color.WHITE,
    val valueFontSize: Int = 48 // Default for Digital
) : Parcelable {
    
    fun getWidgetType(): WidgetType = WidgetType.valueOf(widgetType)
    fun getParameter(): OBDParameter = OBDParameter.valueOf(parameter)
    
    companion object {
        fun create(
            widgetId: Int,
            widgetType: WidgetType,
            parameter: OBDParameter,
            minValue: Float,
            maxValue: Float,
            customLabel: String? = null,
            labelColor: Int = Color.LTGRAY,
            valueColor: Int = Color.WHITE,
            needleColor: Int = Color.RED,
            scaleColor: Int = Color.WHITE,
            valueFontSize: Int = 48
        ): WidgetConfig {
            return WidgetConfig(
                widgetId = widgetId,
                widgetType = widgetType.name,
                parameter = parameter.name,
                minValue = minValue,
                maxValue = maxValue,
                customLabel = customLabel,
                labelColor = labelColor,
                valueColor = valueColor,
                needleColor = needleColor,
                scaleColor = scaleColor,
                valueFontSize = valueFontSize
            )
        }
    }
}

enum class WidgetType {
    ANALOG, DIGITAL, BAR, GAUGE, CIRCULAR
}
