package net.knarcraft.blacksmith.config;

import java.util.Arrays;

public enum GlobalSetting {

    /**
     * The base price for repairing, regardless of durability
     *
     * <p>This allows specifying a price for each item, by setting base-price.item_name.</p>
     */
    BASE_PRICE("global.base-price.default", SettingValueType.POSITIVE_DOUBLE, 10.0, "basePrice"),

    /**
     * The base price for each durability point
     *
     * <p>If natural cost, this is the cost each missing durability point will add to the cost. If not natural cost,
     * this is the cost each present durability point will add to the cost. This allows specifying a price per
     * durability point value for each item, by setting price-per-durability-point.item_name</p>
     */
    PRICE_PER_DURABILITY_POINT("global.price-per-durability-point.default", SettingValueType.POSITIVE_DOUBLE, 0.005, "pricePerDurabilityPoint"),

    /**
     * The price increase for each level of each present enchantment
     *
     * <p>This can be specified for each possible enchantment by setting enchantment-cost.enchantment_name</p>
     */
    ENCHANTMENT_COST("global.enchantment-cost.default", SettingValueType.POSITIVE_DOUBLE, 5.0, "enchantmentCost"),

    /**
     * Whether the cost should increase for damage taken, as opposed to increase for durability present
     */
    NATURAL_COST("global.natural-cost", SettingValueType.BOOLEAN, true, "useNaturalCost");

    private final String path;
    private final String parent;
    private final String commandName;
    private final Object value;
    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>
     */
    GlobalSetting(String path, SettingValueType valueType, Object value, String commandName) {
        this.path = path;
        this.value = value;
        this.commandName = commandName;
        this.valueType = valueType;
        String[] pathParts = path.split("\\.");
        this.parent = String.join(".", Arrays.copyOfRange(pathParts, 0, pathParts.length - 1));
    }

    /**
     * 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 parent item of the defined path
     *
     * @return <p>The parent node</p>
     */
    public String getParent() {
        return parent;
    }

    /**
     * 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 value type for this setting
     *
     * @return <p>The value type for this setting</p>
     */
    public SettingValueType getValueType() {
        return this.valueType;
    }

}
