package com.marvinelsen.willow.ui

import com.marvinelsen.willow.domain.DictionaryEntry
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty
import javafx.collections.FXCollections
import javafx.collections.ObservableList

data class DictionaryEntryFx(
    val traditionalProperty: StringProperty,
    val simplifiedProperty: StringProperty,
    val pinyinWithToneMarksProperty: StringProperty,
    val pinyinWithToneNumbersProperty: StringProperty,
    val zhuyinProperty: StringProperty,
    val definitions: ObservableList<List<String>>,
)

fun DictionaryEntry.toFx() = DictionaryEntryFx(
    traditionalProperty = SimpleStringProperty(this.traditional),
    simplifiedProperty = SimpleStringProperty(this.simplified),
    pinyinWithToneMarksProperty = SimpleStringProperty(this.pinyinWithToneMarks),
    pinyinWithToneNumbersProperty = SimpleStringProperty(this.pinyinWithToneNumbers),
    zhuyinProperty = SimpleStringProperty(this.zhuyin),
    definitions = FXCollections.observableList(this.definitions)
)

fun DictionaryEntryFx.toDomain() = DictionaryEntry(
    traditional = this.traditionalProperty.value,
    simplified = this.simplifiedProperty.value,
    pinyinWithToneMarks = this.pinyinWithToneMarksProperty.value,
    pinyinWithToneNumbers = this.pinyinWithToneNumbersProperty.value,
    zhuyin = this.zhuyinProperty.value,
    definitions = this.definitions.toList()
)
