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

import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType


enum class SettingRow : RowRepresentable {

	// About
	SUBSCRIPTION,
	VERSION,
	RATE_APP,
	CONTACT_US,
	BUG_REPORT,

	// Follow
	FOLLOW_US,

	// Preferences
	LANGUAGE,
	CURRENCY,

	// Data management
	CUSTOM_FIELD,
	BANKROLL,
	GAME,
	LOCATION,
	TOURNAMENT_NAME,
	TOURNAMENT_FEATURE,
	TRANSACTION,
	TRANSACTION_TYPE,

	// Terms
	PRIVACY_POLICY,
	TERMS_OF_USE,
	GDPR;


	companion object {
		/**
		 * Return the rows to display for the current session state
		 */
		fun getRows(): ArrayList<RowRepresentable> {

			val rows = ArrayList<RowRepresentable>()
			rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.information))
			rows.addAll(arrayListOf(SUBSCRIPTION, VERSION, RATE_APP, CONTACT_US, BUG_REPORT))

			rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.follow_us))
			rows.addAll(arrayListOf(FOLLOW_US))

			rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.preferences))
			rows.addAll(arrayListOf(CURRENCY))

			rows.add(
				CustomizableRowRepresentable(
					customViewType = RowViewType.HEADER_TITLE,
					resId = R.string.data_management
				)
			)
			rows.addAll(arrayListOf(CUSTOM_FIELD, GAME, LOCATION, TOURNAMENT_NAME, TOURNAMENT_FEATURE, TRANSACTION_TYPE))

			rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.terms))
			rows.addAll(arrayListOf(PRIVACY_POLICY, TERMS_OF_USE, GDPR))

			return rows
		}

	}

	override val resId: Int?
		get() {
			this.relatedResultsRepresentable?.let {
				return it.pluralResId
			} ?: run {
				return when (this) {
					SUBSCRIPTION -> R.string.subscription
					VERSION -> R.string.version
					RATE_APP -> R.string.releasenote_rating
					CONTACT_US -> R.string.contact
					BUG_REPORT -> R.string.bug_report
					PRIVACY_POLICY -> R.string.privacy_policy
					TERMS_OF_USE -> R.string.terms_of_use
					FOLLOW_US -> R.string.follow_us
					LANGUAGE -> R.string.language
					CURRENCY -> R.string.currency
					GDPR -> R.string.gdpr
					else -> null
				}
			}
		}


	override val viewType: Int
		get() {
			return when (this) {
				VERSION, SUBSCRIPTION -> RowViewType.TITLE_VALUE.ordinal
				LANGUAGE, CURRENCY -> RowViewType.TITLE_VALUE_ARROW.ordinal
				FOLLOW_US -> RowViewType.ROW_FOLLOW_US.ordinal
				else -> RowViewType.TITLE_ARROW.ordinal
			}
		}

	override val relatedResultsRepresentable: LiveData?
		get() {
			return when (this) {
				CUSTOM_FIELD -> LiveData.CUSTOM_FIELD
				BANKROLL -> LiveData.BANKROLL
				GAME -> LiveData.GAME
				LOCATION -> LiveData.LOCATION
				TOURNAMENT_NAME -> LiveData.TOURNAMENT_NAME
				TOURNAMENT_FEATURE -> LiveData.TOURNAMENT_FEATURE
				TRANSACTION -> LiveData.TRANSACTION
				TRANSACTION_TYPE -> LiveData.TRANSACTION_TYPE
				else -> null
			}
		}
}