package net.pokeranalytics.android.model.extensions

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

enum class SessionState {
	PENDING,
	STARTED,
	PAUSED,
	FINISHED,
	INVALID;
}

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

	if (timeFrame == null) {
		return SessionState.PENDING
	}

	val endDate = timeFrame?.endDate
	timeFrame?.let {sessionTimeFrame ->
		timeFrame?.startDate?.let {startDate ->
			if (startDate > Date()) {
				return SessionState.PENDING
			} else if (endDate != null) {
				return SessionState.FINISHED
			} else if (sessionTimeFrame.paused) {
				return SessionState.PAUSED
			} else {
				return SessionState.STARTED
			}
		}
	}

	return SessionState.INVALID
}
