package com.fieldlabel.collector.data.local

import androidx.room.Entity
import androidx.room.PrimaryKey
import com.fieldlabel.collector.domain.model.CustomFieldDef

@Entity(tableName = "custom_field_defs")
data class CustomFieldDefEntity(
    @PrimaryKey val id: String,
    val label: String,
    val unit: String,
    val valueType: String,   // "text" | "number"
    val appliesTo: String,   // "specimen" | "location" | "both"
    val sortOrder: Int
) {
    fun toDomain() = CustomFieldDef(
        id         = id,
        label      = label,
        unit       = unit,
        valueType  = valueType,
        appliesTo  = appliesTo,
        sortOrder  = sortOrder
    )

    companion object {
        fun fromDomain(d: CustomFieldDef) = CustomFieldDefEntity(
            id        = d.id,
            label     = d.label,
            unit      = d.unit,
            valueType = d.valueType,
            appliesTo = d.appliesTo,
            sortOrder = d.sortOrder
        )
    }
}
