package dev.fyloz.plannervio.core.model

import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleLongProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import tornadofx.getValue
import tornadofx.setValue
import java.time.LocalDateTime

open class Board(
        id: Long,
        name: String,
        description: String,
        remote: Boolean = false,
        location: String? = null,
        private: Boolean = false,
        favorite: Boolean = false,
        lastVisited: LocalDateTime? = null
) {
    val idProperty by lazy { SimpleLongProperty(this, "id", id) }
    var id: Long by idProperty

    val nameProperty by lazy { SimpleStringProperty(this, "name", name) }
    var name: String by nameProperty

    val descriptionProperty by lazy { SimpleStringProperty(this, "description", description) }
    var description: String by descriptionProperty

    val remoteProperty by lazy { SimpleBooleanProperty(this, "remote", remote) }
    var isRemote: Boolean by remoteProperty

    val locationProperty by lazy { SimpleStringProperty(this, "location", location) }
    var location: String? by locationProperty

    val privateProperty by lazy { SimpleBooleanProperty(this, "private", private) }
    var isPrivate: Boolean by privateProperty

    val favoriteProperty by lazy { SimpleBooleanProperty(this, "favorite", favorite) }
    var favorite: Boolean by favoriteProperty

    val lastVisitedProperty by lazy { SimpleObjectProperty(this, "lastVisited", lastVisited) }
    var lastVisited: LocalDateTime? by lastVisitedProperty
}

/** DSL for [Board]s. */
fun board(
        id: Long = 0L,
        name: String = "board_name",
        description: String = "board_description",
        remote: Boolean = false,
        location: String? = null,
        private: Boolean = false,
        favorite: Boolean = false,
        lastVisited: LocalDateTime? = null,
        op: Board.() -> Unit = {}
) = Board(id, name, description, remote, location, private, favorite, lastVisited).apply(op)
