using ClaudeDo.Data.Environment;

namespace ClaudeDo.Installer.Checks;

/// <summary>Builds a (FileName, Arguments) pair for a resolved executable, routing shims through cmd.exe.</summary>
internal static class ProcessCommand
{
    public static (string FileName, string Arguments) For(ResolvedExecutable resolved, params string[] args)
    {
        if (resolved.IsShim)
        {
            var shim = ExecutableResolver.BuildShimStartInfo(resolved.Path, args);
            return (shim.FileName, shim.Arguments);
        }

        return (resolved.Path, string.Join(' ', args.Select(Quote)));
    }

    private static string Quote(string value) => value.Contains(' ') ? $"\"{value}\"" : value;
}
