package net.moonleay.gimble.editor

import net.moonleay.gimble.build.BuildConstants
import net.moonleay.gimble.editor.state.EditorState
import net.moonleay.gimble.editor.state.mode.Capability
import net.moonleay.gimble.editor.util.EditorUtil
import org.apache.logging.log4j.LogManager
import java.util.*

object ServerEditorManager {
    private val LOGGER = LogManager.getLogger(BuildConstants.modName)

    private val STATEMAP = mutableMapOf<UUID, EditorState>()

    fun updateEditorState(playerUUID: UUID, editorState: EditorState) {
        STATEMAP[playerUUID] = editorState
        LOGGER.info("$playerUUID: ${editorState.editorMode} with ${editorState.editorModifier}")
    }


    /*
        * Check if a player should be able to perform an action
        * */
    fun shouldPlayer(playerUUID: UUID, capability: Capability): Boolean {
        if (!STATEMAP.containsKey(playerUUID))
            return false
        val state = STATEMAP[playerUUID]!!
        return EditorUtil.shouldPlayer(capability, state)
    }


//    fun playerHasModifier(playerUUID: UUID, modifier: ModeModifier): Boolean {
//        if (!STATEMAP.containsKey(playerUUID))
//            return false
//        return STATEMAP[playerUUID]!!.editorModifier.contains(modifier) ?: false
//    }
}
