package eu.mhsl.minenet.minigames.instance.game.stateless.config;

import eu.mhsl.minenet.minigames.instance.game.Game;
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionHandler;
import eu.mhsl.minenet.minigames.instance.room.Room;
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
import net.minestom.server.item.Material;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface GameFactory {
    TranslatedComponent name();
    default ConfigManager configuration() {
        return null;
    }
    default RestrictionHandler globalRestrictions() {
        return new RestrictionHandler();
    }

    default Material symbol() {
        return Material.GRASS_BLOCK;
    }
    default TranslatedComponent description() {
        return TranslatedComponent.byId("GameFactory#missingDescription");
    }

    Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception;

    default Game manufacture(Room parent, List<Option<?>> configuration) throws Exception {
        if(configuration == null) return manufacture(parent);

        Map<String, Option<?>> cnf = new HashMap<>();
        configuration.forEach(option -> cnf.put(option.getId(), option));

        return manufacture(parent, cnf);
    }

    default Game manufacture(Room parent) throws Exception {
        if(this.configuration() == null) return manufacture(parent, List.of());

        return manufacture(parent, this.configuration().getAll());
    }
}
