package cad97.anden.tact.model

import cad97.anden.data.*
import cad97.fx.observable
import javafx.collections.ObservableMap
import tornadofx.getProperty
import tornadofx.property

class PlayerProperty {
    val inventory: ObservableMap<String, Int> = mutableMapOf<String, Int>().observable()
    val stats: StatsProperty = StatsProperty()
    val flags: ObservableMap<String, Boolean> = mutableMapOf<String, Boolean>().observable()

    fun asPlayer() = Player(
            inventory = Inventory(inventory),
            stats = stats.asStats(),
            flags = Flags(flags)
    )
}

class StatsProperty {
    var health: Int by property<Int>()
    var dodge: Int by property<Int>()
    val attack: StatTripleProperty = StatTripleProperty()
    val defense: StatTripleProperty = StatTripleProperty()

    fun healthProperty() = getProperty(StatsProperty::health)
    fun dodgeProperty() = getProperty(StatsProperty::dodge)

    init {
        health = 0
        dodge = 0
    }

    fun asStats() = Stats(
            health = health,
            dodge = dodge,
            attack = attack.asStatTriple(),
            defense = defense.asStatTriple()
    )
}

class StatTripleProperty {
    var bashing: Int by property<Int>()
    var piercing: Int by property<Int>()
    var slashing: Int by property<Int>()

    fun bashingProperty() = getProperty(StatTripleProperty::bashing)
    fun piercingProperty() = getProperty(StatTripleProperty::piercing)
    fun slashingProperty() = getProperty(StatTripleProperty::slashing)

    init {
        bashing = 0
        piercing = 0
        slashing = 0
    }

    fun asStatTriple() = StatTriple(
            bashing = bashing,
            piercing = piercing,
            slashing = slashing
    )
}
