package inn.ocsf.bee.freigeld.core.repo

import inn.ocsf.bee.freigeld.core.model.CoinValue
import inn.ocsf.bee.freigeld.core.model.data.CoinData
import inn.ocsf.bee.freigeld.core.model.data.CoinStatus
import org.springframework.data.mongodb.core.MongoOperations
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
import javax.inject.Inject

open class CoinRepositoryImpl : CoinRepositoryCustom {

    @Inject
    private lateinit var mongo: MongoOperations

    override fun create(value: CoinValue, era: Int): CoinData {
        val ret = CoinData()
        ret.coin = CoinData.CoinImpl(value, era)
        ret.status = CoinStatus.indoor
        return ret
    }

    override fun getOverall(): Long {
        return (mongo.findOne(Query.query(Criteria.where("_id").`is`("overall")), HashMap::class.java, "coin-overall-view")?.get("amount") as Long?) ?: 0L
    }


}