package ru.dbotthepony.kstarbound.world.api

import com.google.common.collect.ImmutableMap

// uint8_t
enum class TileColor {
	DEFAULT,
	RED,
	BLUE,
	GREEN,
	YELLOW,
	BROWN,
	PURPLE,
	BLACK,
	WHITE;

	val lowercase = name.lowercase()

	companion object {
		private val map: ImmutableMap<String, TileColor>

		init {
			val builder = ImmutableMap.Builder<String, TileColor>()

			for (entry in entries) {
				builder.put(entry.name, entry)
				builder.put(entry.name.lowercase(), entry)
			}

			map = builder.build()
		}

		fun of(index: Int): TileColor {
			return entries.getOrElse(index) { DEFAULT }
		}

		fun of(name: String): TileColor {
			return map[name] ?: map[name.lowercase()] ?: DEFAULT
		}
	}
}
