package net.pokeranalytics.android.ui.view.rowrepresentable

import android.text.InputType
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType

/*

sealed class FilterElement : RowRepresentable {
	class Cash : FilterElement()
	class Tournament : FilterElement()
	data class Game(val game: net.pokeranalytics.android.model.realm.Game) : FilterElement()


	var value : Any? = null

	override val resId: Int?
		get() {
			return when (this) {
				is Cash -> R.string.cash_game
				is Tournament -> R.string.tournament
				else -> null
			}
		}

	override val viewType: Int
		get() {
			return when (this) {
				else -> RowViewType.TITLE_CHECK.ordinal
			}
		}

}
 */
enum class FilterRow : RowRepresentable {

	// General
	CASH_GAME,
	TOURNAMENT,
	LIVE,
	ONLINE,

	// Date
	TODAY,
	YESTERDAY,
	TODAY_AND_YESTERDAY,
	CURRENT_WEEK,
	CURRENT_MONTH,
	CURRENT_YEAR,
	FROM,
	TO,
	PAST_DAYS,
	WEEKDAYS,
	WEEKEND,

	;

	override val resId: Int?
		get() {
			return when (this) {
				CASH_GAME -> R.string.cash_game
				TOURNAMENT -> R.string.tournament
				LIVE -> R.string.live
				ONLINE -> R.string.online
				TODAY -> R.string.today
				YESTERDAY -> R.string.yesterday
				TODAY_AND_YESTERDAY -> R.string.yesterday_and_today
				CURRENT_WEEK -> R.string.current_week
				CURRENT_MONTH -> R.string.current_month
				CURRENT_YEAR -> R.string.current_year
				FROM -> R.string.from
				TO -> R.string.to
				PAST_DAYS -> R.string.period_in_days
				WEEKDAYS -> R.string.week_days
				WEEKEND -> R.string.weekend
				else -> null
			}
		}

	override val viewType: Int
		get() {
			return when (this) {
				FROM, TO -> RowViewType.TITLE_VALUE_CHECK.ordinal
				else -> RowViewType.TITLE_CHECK.ordinal
			}
		}

	override fun excludedFilterRows(): ArrayList<FilterRow>? {
		return when (this) {
			CASH_GAME, TOURNAMENT -> arrayListOf(CASH_GAME, TOURNAMENT)
			LIVE, ONLINE -> arrayListOf(LIVE, ONLINE)
			else -> ArrayList()
		}
	}

	override fun excludedFilterSubcategoryRows(): ArrayList<FilterSubcategoryRow>? {
		return when (this) {
			TODAY, YESTERDAY, TODAY_AND_YESTERDAY, CURRENT_WEEK, CURRENT_MONTH, CURRENT_YEAR -> arrayListOf(FilterSubcategoryRow.FIXED_DATE)
			FROM, TO -> arrayListOf(FilterSubcategoryRow.DYNAMIC_DATE)
			else -> null
		}
	}

	override fun subcategoryRow(): FilterSubcategoryRow? {
		return when (this) {
			CASH_GAME, TOURNAMENT -> FilterSubcategoryRow.TOURNAMENT_TYPE
			LIVE, ONLINE -> FilterSubcategoryRow.LIVE_ONLINE
			TODAY, YESTERDAY, TODAY_AND_YESTERDAY, CURRENT_WEEK, CURRENT_MONTH, CURRENT_YEAR -> FilterSubcategoryRow.DYNAMIC_DATE
			FROM, TO -> FilterSubcategoryRow.FIXED_DATE
			PAST_DAYS -> FilterSubcategoryRow.DURATION
			WEEKDAYS, WEEKEND -> FilterSubcategoryRow.WEEKDAYS_OR_WEEKEND
			else -> null
		}
	}

	override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
		when (this) {
			PAST_DAYS -> {
				val defaultValue: String? by map
				val data = arrayListOf<RowRepresentableEditDescriptor>()
				data.add(
					RowRepresentableEditDescriptor(
						defaultValue,
						inputType = InputType.TYPE_CLASS_NUMBER
					)
				)
			}
		}

		return super.editingDescriptors(map)
	}

}