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

import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.CustomField
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType

enum class CustomFieldRow : RowRepresentable, DefaultEditDataSource {
	TYPE,
	COPY_ON_DUPLICATE;

	override val resId: Int?
		get() {
			return when (this) {
				COPY_ON_DUPLICATE -> R.string.copy_on_duplicate
				else -> null
			}
		}

	override val viewType: Int
		get() {
			return when (this) {
				TYPE -> RowViewType.LIST.ordinal
				COPY_ON_DUPLICATE -> RowViewType.TITLE_SWITCH.ordinal
			}
		}

	override val bottomSheetType: BottomSheetType
		get() {
			return when (this) {
				TYPE -> BottomSheetType.NONE
				COPY_ON_DUPLICATE -> BottomSheetType.NONE
			}
		}


	override val choices: List<CustomField.Type>?
		get() {
			return when (this) {
				TYPE -> CustomField.Type.values().toList()
				else -> null
			}
		}

	fun getChoices(currentChoiceIndex: Int, isUpdating: Boolean): List<CustomField.Type>? {
		val list = CustomField.Type.values().toList()
		list.forEach { type ->
			type.isEnabled = if (!isUpdating) {
				true
			} else {
				!(currentChoiceIndex == CustomFieldRow.TYPE.ordinal || type == CustomField.Type.LIST)
			}
		}
		return list
	}
}