package net.pokeranalytics.android.model.realm

import io.realm.RealmObject
import net.pokeranalytics.android.calculus.interfaces.Computable

open class ComputableResult : RealmObject(), Computable {

	override var ratedNet: Double = 0.0

	override var bbNetResult: Double = 0.0

	override var hasBigBlind: Int = 0

	override var isPositive: Int = 0

	override var ratedBuyin: Double = 0.0

	override var estimatedHands: Double = 0.0

	override var bbPer100Hands: Double = 0.0

	override var sessionSet: SessionSet? = null

//	@LinkingObjects("computableResult")
//	private val sessions: RealmResults<Session>? = null

//	@Ignore
	var session: Session? = null

	fun updateWith(session: Session) {

		val rate = session.bankroll?.currency?.rate ?: 1.0

		session.result?.let { result ->
			this.ratedNet = result.net * rate
			this.isPositive = result.isPositive
			this.ratedBuyin = (result.buyin ?: 0.0) * rate
		}
		this.bbNetResult = session.bbNetResult
		this.hasBigBlind = session.hasBigBlind
		this.estimatedHands = session.estimatedHands
		this.bbPer100Hands = session.bbPer100Hands

		this.sessionSet = session.sessionSet

	}

	enum class Field(val identifier: String) {
		RATED_NET("ratedNet"),
		BB_NET("bbNetResult"),
		HAS_BIG_BLIND("hasBigBlind"),
		IS_POSITIVE("isPositive"),
		RATED_BUYIN("ratedBuyin"),
		ESTIMATED_HANDS("estimatedHands"),
		BB_PER100HANDS("bbPer100Hands")
	}

}
