using Mlaumcherb.Client.Avalonia.зримое;

namespace Mlaumcherb.Client.Avalonia.холопы;

public static class PathHelper
{
    public static IOPath GetRootFullPath() =>
        System.IO.Path.GetFullPath(new IOPath(LauncherApp.Config.minecraft_dir).ToString());
    
    public static IOPath GetAssetsDir() => 
        Path.Concat(GetRootFullPath(), "assets");
    
    public static IOPath GetAssetIndexFilePath(string id) => 
        Path.Concat(GetAssetsDir(), $"indexes/{id}.json"); // this path is hardcoded in the game
    
    public static IOPath GetVersionDescriptorPath(string id) => 
        Path.Concat(GetVersionDir(id), id + ".json");

    public static IOPath GetVersionsDir() => 
        Path.Concat(GetRootFullPath(), "versions");
    
    public static IOPath GetVersionDir(string id) => 
        Path.Concat(GetVersionsDir(), id);

    public static IOPath GetVersionJarFilePath(string id) =>
        Path.Concat(GetVersionDir(id), id + ".jar");
    
    public static IOPath GetLibrariesDir() => 
        Path.Concat(GetRootFullPath(), "libraries");

    public static IOPath GetNativeLibrariesDir(string id) =>
        Path.Concat(GetVersionDir(id), "natives", PlatformHelper.GetOsAndArch());
    
    public static IOPath GetJavaRuntimesDir() => 
        Path.Concat(GetRootFullPath(), "java");
    
    
    public static IOPath GetJavaRuntimeDir(string id) => 
        Path.Concat(GetJavaRuntimesDir(), PlatformHelper.GetOsAndArch(), id);

    public static IOPath GetJavaBinDir(string id) =>
        Path.Concat(GetJavaRuntimeDir(id), "bin");
    public static IOPath GetJavaExecutablePath(string id, bool redirectOutput)
    {
        string executable_name = "java";
        if (!redirectOutput)
            executable_name = "javaw";
        if(OperatingSystem.IsWindows())
            executable_name += ".exe";
        var path = Path.Concat(GetJavaBinDir(id), executable_name);
        if(!redirectOutput && !File.Exists(path))
            return GetJavaExecutablePath(id, true);
        return path;
    }

    public static string GetLog4jConfigFileName() => "log4j.xml";
    
    public static IOPath GetLog4jConfigFilePath() =>
        Path.Concat(GetAssetsDir(), GetLog4jConfigFileName());

    public static IOPath GetModpackDescriptorPath(string game_version) => 
        Path.Concat(GetVersionDir(game_version), "timerix_modpack.json");

    public static IOPath GetCacheDir() =>
        Path.Concat(GetRootFullPath(), "cache");
    public static IOPath GetInstalledVersionCatalogPath() =>
        Path.Concat(GetCacheDir(), "installed_versions.json");
}
