package cn.hamster3.mc.auth.config;

import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Map;

public class NeteaseServerConfig {
    private static boolean loaded = false;
    private static String authUrl = "http://192.168.0.100:9999/check";
    private static String gameId = "12345678901234567";

    static {
        init();
    }

    @SuppressWarnings("CallToPrintStackTrace")
    public static void init() {
        if (loaded) {
            return;
        }
        loaded = true;
        File file = new File("netease.yml");
        if (!file.exists()) {
            try (InputStream stream = NeteaseServerConfig.class.getResourceAsStream("/netease.yml")) {
                if (stream != null) {
                    Files.copy(stream, file.toPath());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        try {
            String readString = Files.readString(file.toPath());
            Map<String, String> map = new Yaml().load(readString);
            authUrl = map.getOrDefault("auth-url", "http://192.168.0.100:9999/check");
            gameId = map.getOrDefault("game-id", "12345678901234567");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getAuthUrl() {
        return authUrl;
    }

    public static String getGameId() {
        return gameId;
    }
}
