package net.pokeranalytics.android.model.realm

import io.realm.Realm
import io.realm.RealmObject
import io.realm.RealmResults
import io.realm.annotations.Ignore
import io.realm.annotations.LinkingObjects


open class SessionSet() : RealmObject() {

    /**
     * The timeframe of the set, i.e. its start & end date
     */

    var timeFrame: TimeFrame? = null

    /**
     * The list of sessions associated with this set
     */
    @LinkingObjects("sessionSet")
    val sessions: RealmResults<Session>? = null

    @Ignore // a duration shortcut
    var duration: Long = 0L
        get() {
            return this.timeFrame?.duration ?: 0L
        }

    @Ignore // a duration in hour
    var hourlyDuration: Double = 0.0
        get() {
            return this.timeFrame?.hourlyDuration ?: 0.0
        }

    @Ignore // a netResult shortcut
    var netResult: Double = 0.0
        get () {
            return this.sessions?.sumByDouble { it.value } ?: 0.0
        }

    @Ignore // a duration shortcut
    var hourlyRate: Double = 0.0

    @Ignore
    var estimatedHands: Double = 25.0 * (this.timeFrame?.hourlyDuration?.toDouble() ?: 0.0)

    @Ignore
    var bbNetResult: Double = 0.0

    companion object {

        fun newInstance(realm: Realm) : SessionSet {
            val sessionSet: SessionSet = realm.createObject(SessionSet::class.java)
            sessionSet.timeFrame = realm.createObject(TimeFrame::class.java)
            return sessionSet
        }

    }


}

