package net.knarcraft.blacksmith.config;

import java.util.Arrays;

/**
 * An enum representing all of Blacksmith's settings
 */
public enum NPCSetting {

    DROP_ITEM("defaults.drop-item", SettingValueType.BOOLEAN, true, "dropItem"),
    DISABLE_COOL_DOWN("defaults.disable-cool-down", SettingValueType.BOOLEAN, false, "disableCoolDown"),
    DISABLE_DELAY("defaults.disable-delay", SettingValueType.BOOLEAN, false, "disableDelay"),
    FAIL_CHANCE("defaults.percent-chance-to-fail-reforge", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
    EXTRA_ENCHANTMENT_CHANCE("defaults.percent-chance-for-extra-enchantment", SettingValueType.PERCENTAGE, 5,
            "extraEnchantmentChance"),
    MAX_ENCHANTMENTS("defaults.maximum-enchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"),
    MAX_REFORGE_DELAY("defaults.delays-in-seconds.maximum", SettingValueType.POSITIVE_INTEGER, 30, "maxReforgeDelay"),
    MIN_REFORGE_DELAY("defaults.delays-in-seconds.minimum", SettingValueType.POSITIVE_INTEGER, 5, "minReforgeDelay"),
    REFORGE_COOL_DOWN("defaults.delays-in-seconds.reforge-cool-down", SettingValueType.POSITIVE_INTEGER, 60, "reforgeCoolDown"),
    REFORGE_ABLE_ITEMS("defaults.reforge-able-items", SettingValueType.STRING_LIST, new String[]{}, "reforgeAbleItems"),

    /*-----------
     | Messages |
     -----------*/
    BUSY_WITH_PLAYER_MESSAGE("defaults.messages.busy-with-player", SettingValueType.STRING,
            "&cI'm busy at the moment. Come back later!", "busyPlayerMessage"),
    //TODO: Add placeholder for remaining time?
    BUSY_WITH_REFORGE_MESSAGE("defaults.messages.busy-with-reforge", SettingValueType.STRING,
            "&cI'm working on it. Be patient!", "busyReforgeMessage"),
    //TODO: Add placeholder for remaining time?
    COOL_DOWN_UNEXPIRED_MESSAGE("defaults.messages.cool-down-not-expired", SettingValueType.STRING,
            "&cYou've already had your chance! Give me a break!", "coolDownUnexpiredMessage"),
    COST_MESSAGE(
            "defaults.messages.cost", SettingValueType.STRING,
            "&eIt will cost &a<price> &eto reforge that &a<item>&e! Click again to reforge!", "costMessage"),
    FAIL_MESSAGE("defaults.messages.fail-reforge", SettingValueType.STRING, "&cWhoops! Didn't mean to do that! Maybe next time?",
            "failReforgeMessage"),
    INSUFFICIENT_FUNDS_MESSAGE("defaults.messages.insufficient-funds", SettingValueType.STRING,
            "&cYou don't have enough money to reforge that item!", "insufficientFundsMessage"),
    INVALID_ITEM_MESSAGE("defaults.messages.invalid-item", SettingValueType.STRING,
            "&cI'm sorry, but I don't know how to reforge that!", "invalidItemMessage"),
    ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("defaults.messages.item-changed-during-reforge", SettingValueType.STRING,
            "&cThat's not the item you wanted to reforge before!", "itemChangedMessage"),
    START_REFORGE_MESSAGE("defaults.messages.start-reforge", SettingValueType.STRING,
            "&eOk, let's see what I can do...", "startReforgeMessage"),
    SUCCESS_MESSAGE("defaults.messages.successful-reforge", SettingValueType.STRING,
            "There you go! All better!", "successMessage");

    private final String path;
    private final String childPath;
    private final Object value;
    private final String commandName;
    private final String nodeName;
    private final SettingValueType valueType;

    /**
     * Instantiates a new setting
     *
     * @param path        <p>The full config path for this setting</p>
     * @param valueType   <p>The type of value used by this setting</p>
     * @param value       <p>The default value of this setting</p>
     * @param commandName <p>The name of the command used to change this setting</p>
     */
    NPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
        this.path = path;
        this.value = value;
        this.valueType = valueType;
        String[] pathParts = path.split("\\.");
        this.childPath = String.join(".", Arrays.copyOfRange(pathParts, 1, pathParts.length));
        this.commandName = commandName;
        if (pathParts.length > 0) {
            this.nodeName = pathParts[pathParts.length - 1];
        } else {
            this.nodeName = "";
        }
    }

    /**
     * Gets the full config path for this setting
     *
     * @return <p>The full config path for this setting</p>
     */
    public String getPath() {
        return path;
    }

    /**
     * Gets the config path without the root node
     *
     * @return <p>The config path without the root node</p>
     */
    public String getChildPath() {
        return childPath;
    }

    /**
     * Gets the value of this setting
     *
     * @return <p>The value of this setting</p>
     */
    public Object getDefaultValue() {
        return value;
    }

    /**
     * The name of the command used to change this setting
     *
     * @return <p>The name of this setting's command</p>
     */
    public String getCommandName() {
        return commandName;
    }

    /**
     * Gets the name of this configuration node
     *
     * @return <p>The name of this configuration node</p>
     */
    public String getNodeName() {
        return nodeName;
    }

    /**
     * Gets the value type for this setting
     *
     * @return <p>The value type for this setting</p>
     */
    public SettingValueType getValueType() {
        return this.valueType;
    }

}
