package net.pokeranalytics.android.model.migrations

import io.realm.Realm
import net.pokeranalytics.android.model.filter.Query
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.model.realm.Result
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.SessionSet

class Patcher {

	companion object {

		fun patchBreaks() {

			val realm = Realm.getDefaultInstance()
			val sets = realm.where(SessionSet::class.java).findAll()
			val sessions = Filter.queryOn<Session>(realm, Query(QueryCondition.IsCash))
            val results = realm.where(Result::class.java).findAll()

			realm.executeTransaction {
				sets.forEach {
					it.computeStats()
				}
                sessions.forEach {
                    it.formatBlinds()
                }
                results.forEach {
                    it.computeNumberOfRebuy()
                }
			}
			realm.close()

		}

	}


}