package de.steamwar.tntleague.config

import de.steamwar.tntleague.plugin
import org.bukkit.Material
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.configuration.file.FileConfiguration

data class TNTLeagueConfig(
    val startDelay: Int = 10,
    val gameTime: Int = 60 * 20,

    val prices: Map<Material, Price>
) {
    companion object {
        val config: TNTLeagueConfig by lazy { loadConfig(plugin.config) }

        private fun loadConfig(config: FileConfiguration): TNTLeagueConfig {
            return TNTLeagueConfig(config.getInt("startDelay"), config.getInt("gameTime"), loadPrices(config.getConfigurationSection("prices")!!))
        }

        private fun loadPrices(config: ConfigurationSection): Map<Material, Price> {
            return config.getKeys(false).associateWith {
                Price(
                    config.getInt("$it.amount"),
                    config.getInt("$it.price")
                )
            }.mapKeys { Material.getMaterial(it.key)!! }
        }
    }

    data class Price(
        val amount: Int,
        val price: Int,
    )
}
