package com.marvinelsen.willow.ui

import com.marvinelsen.willow.domain.CrossStraitsDefinition
import com.marvinelsen.willow.domain.DictionaryEntry
import com.marvinelsen.willow.domain.MoedictDefinition
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 cedictDefinitions: ObservableList<List<String>>,
    val crossStraitsDefinitions: ObservableList<CrossStraitsDefinition>,
    val moedictDefinitions: ObservableList<MoedictDefinition>,
)

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

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