package inn.ocsf.bee.freigeld.core.model

import java.util.*
import kotlin.math.max

class CoinDescrInv(val _value: CoinValue, var cashback: Long, var _era: Int) : Coin {

    init {
        if (cashback >= 0) throw IllegalArgumentException("cashback must be negative")
    }

    override fun getEra(): Int {
        return _era
    }

    override fun incEra() {
        this._era = max(0, this._era - 1)
        this.cashback = max(0, cashback + _value.delta)
    }

    override fun getId(): UUID? {
        return null
    }

    override fun getValue(): CoinValue {
        return _value
    }

    override fun getCurrent(): Long {
        return cashback
    }

    override fun toString(): String {
        return "${value} jdc${era} (${current})"
    }

    /*fun invert(): DemoFutureCoin {
        var newEra = maxEraValue - _era
        if (newEra == maxEraValue) newEra = 0
        var newCurrent = value.amount + cashback
        if (newCurrent == 0L) newCurrent = value.amount
        val ret = DemoFutureCoin(_value, newEra)
        if (ret.current != newCurrent)
            throw IllegalArgumentException("wrong inverted coin")
        return ret
    }*/
}