package config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

public class ConfLoad {

    public static final String PATH ="config.json";

    public static Configuration load() {
        Configuration conf;
            try {
                InputStream is = new FileInputStream(PATH);
                JSONTokener tokener = new JSONTokener(is);
                JSONObject obj = new JSONObject(tokener);
                conf = new Configuration(obj);
                return conf;
            } catch (FileNotFoundException e) {
                System.out.println("No config file found");
                conf = new Configuration();
                return conf;
            } catch (JSONException e) {
                System.out.println("Could not read config file. Please make sure it is a valid JSON.");
                conf = new Configuration();
                return conf;
            }

    }

    public interface ConfLoadCb {
        void onLoaded(Configuration config);
    }

}
