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

import android.text.InputType
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import java.util.*

interface FilterElementRow : RowRepresentable {
    override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
        return when (this) {
            is QueryCondition.Duration -> {
                val hours: String? by map
                val minutes: String? by map
                arrayListOf(
                    RowRepresentableEditDescriptor(hours, R.string.hour, inputType = InputType.TYPE_CLASS_NUMBER),
                    RowRepresentableEditDescriptor(minutes, R.string.minute, inputType = InputType.TYPE_CLASS_NUMBER)
                )
            }
            is QueryCondition.ListOfValues<*> -> {
                val valueAsString: String? by map
                arrayListOf(
                    RowRepresentableEditDescriptor(valueAsString, this.resId, inputType = InputType.TYPE_CLASS_NUMBER)
                )
            }
            else -> super.editingDescriptors(map)
        }
    }

    var filterSectionRow: FilterSectionRow

    val sectionToExclude: List<FilterSectionRow>?
        get() {
            val excluded = arrayListOf<FilterSectionRow>()
            if (!this.filterSectionRow.allowMultiSelection) {
                excluded.add(this.filterSectionRow)
            }
            this.filterSectionRow.exclusiveWith?.let { exclusives ->
                excluded.addAll(exclusives)
            }

            if (excluded.size > 0) {
                return excluded
            }
            return null
        }
}