using System.IO;

namespace NexusShell.Services;

internal static class NexusInstallRoot
{
    public static bool TryResolve(out string installRoot)
    {
        installRoot = string.Empty;
        var shellDir = AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
        var candidate = Path.GetFullPath(Path.Combine(shellDir, ".."));

        var identityExe = Path.Combine(candidate, "identity", "NexusIdentity.Api.exe");
        var shellExe = Path.Combine(candidate, "shell", "NexusShell.exe");

        if (!File.Exists(identityExe) || !File.Exists(shellExe))
        {
            return false;
        }

        installRoot = candidate;
        return true;
    }
}
