package net.minestom.server.utils;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Internal
public final class PropertyUtils {
    private PropertyUtils() {}

    public static boolean getBoolean(String name, boolean defaultValue) {
        boolean result = defaultValue;
        try {
            final String value = System.getProperty(name);
            if (value != null) result = Boolean.parseBoolean(value);
        } catch (IllegalArgumentException | NullPointerException ignored) {
        }
        return result;
    }

    @Contract("_, null -> null; _, !null -> !null")
    public static String getString(@NotNull String name, @Nullable String defaultValue) {
        final String value = System.getProperty(name);

        if (value == null) {
            return defaultValue;
        } else {
            return value;
        }
    }
}
