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

import android.text.InputType
import io.realm.RealmResults
import net.pokeranalytics.android.R
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.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType


enum class TransactionRow : RowRepresentable, DefaultEditDataSource {
    BANKROLL,
    TYPE,
    AMOUNT,
	DATE,
    COMMENT;

    override val resId: Int?
        get() {
            return when (this) {
	            BANKROLL -> R.string.bankroll
	            TYPE -> R.string.type
	            AMOUNT -> R.string.amount
	            COMMENT -> R.string.comment
	            DATE -> R.string.date
            }
        }

    override val viewType: Int
        get() {
            return when (this) {
	            BANKROLL -> RowViewType.TITLE_VALUE.ordinal
	            TYPE -> RowViewType.TITLE_VALUE.ordinal
	            AMOUNT -> RowViewType.TITLE_VALUE.ordinal
	            COMMENT -> RowViewType.TITLE_VALUE.ordinal
	            DATE -> RowViewType.TITLE_VALUE.ordinal
            }
        }

    override val bottomSheetType: BottomSheetType
        get() {
            return when (this) {
	            BANKROLL -> BottomSheetType.LIST
	            TYPE -> BottomSheetType.LIST
	            AMOUNT -> BottomSheetType.EDIT_TEXT
	            COMMENT -> BottomSheetType.EDIT_TEXT_MULTI_LINES
	            DATE -> BottomSheetType.NONE
            }
        }

	override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
		return when (this) {
			BANKROLL -> {
				val defaultValue : Any? by map
				val data : RealmResults<RowRepresentable>? by map
				arrayListOf(
					RowRepresentableEditDescriptor(defaultValue, data = data)
				)
			}
			TYPE -> {
				val defaultValue : Any? by map
				val data : RealmResults<RowRepresentable>? by map
				arrayListOf(
					RowRepresentableEditDescriptor(defaultValue, data = data)
				)
			}
			AMOUNT -> {
				val defaultValue: String? by map
				arrayListOf(
					RowRepresentableEditDescriptor(
						defaultValue,
						inputType = InputType.TYPE_CLASS_NUMBER
								or InputType.TYPE_NUMBER_FLAG_DECIMAL
								or InputType.TYPE_NUMBER_FLAG_SIGNED
					))
			}
			COMMENT -> {
				val defaultValue : String? by map
				arrayListOf(RowRepresentableEditDescriptor(defaultValue, R.string.comment))
			}
			else -> super<RowRepresentable>.editingDescriptors(map)
		}
	}
}