package tech.nevets.jaml;

import org.simpleyaml.configuration.file.YamlFile;

import java.io.IOException;

public class Config {
    private static final YamlFile ymlFile = new YamlFile(JAML.path + "\\config.yml");

    public static void loadConfig() {
        try {
            if (!ymlFile.exists()) {
                System.out.println("Config file not found, creating new one...");
                ymlFile.createNewFile(true);
                System.out.println("Config file created!");
            } else {
                System.out.println("Loading Config file...");
                ymlFile.loadWithComments();
                System.out.println("Config file loaded!");
            }
        } catch (final Exception e) {
            System.out.println("Error while loading config file!");
            e.printStackTrace();
        }

        ymlFile.addDefault("java.jdk8", "");
        ymlFile.addDefault("java.jdk16", "");
        ymlFile.addDefault("java.jdk17", "");
        ymlFile.addDefault("launcher.path","default");
        ymlFile.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
        ymlFile.addDefault("launcher.verbose", false);
        ymlFile.setComment("launcher.verbose", "If true, will print out all the messages");
        ymlFile.addDefault("launcher.version", "0.1.0");
        ymlFile.setComment("launcher.version", "Jaml version, don't change it!");

        try {
            ymlFile.save();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static YamlFile getConfig() {
        return ymlFile;
    }
}
