package net.pokeranalytics.android.model.realm

import io.realm.RealmObject
import net.pokeranalytics.android.model.filter.Filterable
import net.pokeranalytics.android.model.filter.QueryCondition

open class ComputableResult() : RealmObject(), Filterable {

	 var ratedNet: Double = 0.0

	 var bbNet: BB = 0.0

	 var hasBigBlind: Int = 0

	 var isPositive: Int = 0

	 var ratedBuyin: Double = 0.0

	 var estimatedHands: Double = 0.0

	 var bbPer100Hands: BB = 0.0

//	 var sessionSet: SessionSet? = null

	var session: Session? = null

	fun updateWith(session: Session) {

//		this.sessionSet = session.sessionSet

		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.bbNet = session.bbNet
		this.hasBigBlind = if (session.cgBigBlind != null) 1 else 0
		this.estimatedHands = session.estimatedHands
		this.bbPer100Hands = session.bbNet / (session.numberOfHandsPerHour * session.hourlyDuration) * 100

	}

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

	companion object {

		fun fieldNameForQueryType(queryCondition: Class < out QueryCondition >): String? {
            Session.fieldNameForQueryType(queryCondition)?.let {
                return "session.$it"
            }
            return null
		}

	}

}
