package ru.dbotthepony.kstarbound.defs.world

import com.google.gson.JsonObject
import ru.dbotthepony.kstarbound.json.builder.JsonFactory

@JsonFactory
data class InstanceWorldConfig(
	val worldProperties: JsonObject = JsonObject(),
	val spawningEnabled: Boolean = true,
	val persistent: Boolean = false,
	val useUniverseClock: Boolean = false,
	val skyParameters: SkyParameters = SkyParameters(),
	val disableDeathDrops: Boolean = false,
	val beamUpRule: BeamUpRule? = null,

	val type: String,

	val seed: Long? = null,

	// terrestrial
	val planetType: String? = null,
	val planetSize: String? = null,

	// floating dungeon
	val dungeonWorld: String? = null,
) {
	init {
		when (type.lowercase()) {
			"terrestrial" -> {
				requireNotNull(planetSize) { "World has 'type' specified as $type, but is missing 'planetSize' parameter" }
				requireNotNull(planetType) { "World has 'type' specified as $type, but is missing 'planetType' parameter" }
			}

			"floatingdungeon" -> requireNotNull(dungeonWorld) { "World has 'type' specified as $type, but is missing 'dungeonWorld' parameter" }
			"asteroids" -> {}
			else -> throw IllegalArgumentException("Invalid instance world type $type")
		}
	}
}
