package net.pokeranalytics.android.ui.view

import android.content.Context
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSubcategoryRow
import net.pokeranalytics.android.util.NULL_TEXT

/**
 * An interface extending Displayable to add a way to represent an object as a String
 */
interface RowRepresentable : Displayable, Editable, Filterable {

	fun getDisplayName(): String {
		return NULL_TEXT
	}
}

/**
 * An interface used to manage the filters
 */
interface Filterable {
	/**
	 * The subcategory of a filter
	 */
	fun subcategoryRow(): FilterSubcategoryRow? {
		return null
	}

	/**
	 * Return the filter rows to deactivate
	 */
	fun excludedFilterRows(): ArrayList<FilterRow>? {
		return null
	}

	/**
	 * Return the Filter Subcategory rows to deactivate
	 */
	fun excludedFilterSubcategoryRows(): ArrayList<FilterSubcategoryRow>? {
		return null
	}
}

interface Editable {
	fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
		return null
	}
}

interface DefaultEditable : Editable, Localizable {
	override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
		val defaultValue: String? by map
		return arrayListOf(RowRepresentableEditDescriptor(defaultValue, this.resId))
	}
}

/**
 * An interface used so that enums values can be represented visually
 *  as rows in RecyclerViews
 */
interface Displayable : Localizable {

	/**
	 * The type of view associated with the row
	 */
	val viewType: Int
		get() {
			return -1
		}

	val relatedResultsRepresentable: LiveData?
		get() {
			return null
		}

	val bottomSheetType: BottomSheetType
		get() {
			return BottomSheetType.NONE
		}
}

/**
 * An interface to easily localize any object
 */
interface Localizable {

	/**
	 * The resource identifier of the localized title
	 */
	val resId: Int?
		get() {
			return null
		}

	/**
	 * The localized title of the row
	 */
	fun localizedTitle(context: Context): String {
		this.resId?.let {
			return context.getString(it)
		}
		return "LOCALISATION NOT FOUND"
	}
}
