using System.IO;

namespace NexusShell.Services;

/// <summary>
/// Identity SQLite lives outside the versioned install tree so updates can overwrite identity/ binaries.
/// </summary>
public static class NexusIdentityDataPaths
{
    public static string ResolveDataDirectory(string installRoot)
    {
        if (!string.IsNullOrWhiteSpace(installRoot))
        {
            return Path.Combine(installRoot, "data", "identity");
        }

        return Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
            "NinjaNexus",
            "identity");
    }

    public static string ResolveDatabasePath(string installRoot)
    {
        var dataDir = ResolveDataDirectory(installRoot);
        Directory.CreateDirectory(dataDir);
        return Path.Combine(dataDir, "nexus-identity.db");
    }

    public static string BuildConnectionString(string installRoot) =>
        $"Data Source={ResolveDatabasePath(installRoot)}";
}
