package xyz.wbsite.frame.provider;

import xyz.wbsite.frame.base.LocalData;
import xyz.wbsite.frame.utils.StringUtil;

public class SimpleProfileProvider implements ProfileProvider {

    @Override
    public String getString(String key, String defaultValue) {
        return LocalData.getProperty(key, defaultValue);
    }

    @Override
    public int getInt(String key, int defaultValue) {
        String string = getString(key, String.valueOf(defaultValue));
        if (!StringUtil.isEmpty(string)) {
            try {
                return Integer.parseInt(string);
            } catch (Exception ignored) {

            }
        }
        return defaultValue;
    }

    @Override
    public long getLong(String key, long defaultValue) {
        String string = this.getString(key, String.valueOf(defaultValue));
        if (!StringUtil.isEmpty(string)) {
            try {
                return Long.parseLong(string);
            } catch (Exception ignored) {

            }
        }
        return defaultValue;
    }

    @Override
    public boolean getBoolean(String key, boolean defaultValue) {
        String string = this.getString(key, String.valueOf(defaultValue));
        if (!StringUtil.isEmpty(string)) {
            try {
                return Boolean.parseBoolean(string);
            } catch (Exception ignored) {

            }
        }
        return defaultValue;
    }
}
