package net.pokeranalytics.android.model.extensions

import net.pokeranalytics.android.model.realm.Session
import java.util.*

enum class SessionState {
	PENDING,
	PLANNED,
	STARTED,
	PAUSED,
	FINISHED;

	var hasStarted: Boolean = false
		get() {
			return when (this) {
				STARTED, PAUSED, FINISHED -> true
				else -> false
			}
		}
}

/**
 * Return the current state of a session
 * For example: STARTED, PAUSED, FINISHED
 */
fun Session.getState(): SessionState {

//	if (timeFrame == null) {
//		return SessionState.PENDING
//	}
	val start = this.startDate
	if (start == null) {
		return SessionState.PENDING
	} else {
		if (start > Date()) {
			return SessionState.PLANNED
		} else if (this.endDate != null) {
			return SessionState.FINISHED
		} else if (this.pauseDate != null) {
			return SessionState.PAUSED
		} else {
			return SessionState.STARTED
		}
	}

}