package tech.nevets.jaml;

import org.simpleyaml.configuration.file.YamlFile;
import tech.nevets.jaml.gui.GUI;

import java.io.IOException;
import java.nio.file.Path;

public class JAML {
    public static YamlFile config;
    public static Path path;
    public static DiscordRP drp = new DiscordRP();


    public static void main(String[] args) throws InterruptedException {
        makeDirs();
        Config.loadConfig();
        config = Config.getConfig();

        try {
            Profiles.loadProfile("test");
        } catch (IOException e) {
            e.printStackTrace();
        }

//        try {
//            Profiles.createProfile("testing");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        drp.start();

        GUI.startGui();

        drp.shutdown();
    }

    private static void makeDirs() {
        if (config == null) {
            path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
        } else {
            if (config.getString("launcher.path") == "default") {
                path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
            } else {
                path = Path.of(config.getString("launcher.path"));
            }
        }

        try {
            if (!path.toFile().exists()) {
                path.toFile().mkdirs();
            }
        } catch (Exception e) {
            System.out.println("Invalid path, please check your config.yml and try again");
        }

        try {
            Path profilePath = Path.of(path + "\\profiles\\");
            if (!profilePath.toFile().exists()) {
                profilePath.toFile().mkdirs();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            Path profilePath = Path.of(path + "\\assets\\");
            if (!profilePath.toFile().exists()) {
                profilePath.toFile().mkdirs();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    public static void initDiscord() {
//        DiscordEventHandlers handlers = new DiscordEventHandlers.Builder().setReadyEventHandler((user) -> {
//            System.out.println("Welcome " + user.username + "#" + user.discriminator + ".");
//            DiscordRichPresence.Builder presence = new DiscordRichPresence.Builder("");
//            DiscordRPC.discordUpdatePresence(presence.build());
//        }).build();
//        DiscordRPC.discordInitialize("942986640043941938", handlers, false);
//        DiscordRPC.discordRegister("942986640043941938", "");
//    }
}