// PRE-GENERATED (design session). Silent install of local AI runtimes via winget.
// Untested here. winget must be present (Win10 1809+/Win11 usually have it).
using System.Diagnostics;
using System.Threading.Tasks;

namespace DansoriEQ.App.Ai;

public static class WingetInstaller
{
    public static bool IsAvailable()
    {
        try
        {
            var psi = new ProcessStartInfo("winget", "--version")
            { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true };
            using var p = Process.Start(psi);
            if (p == null) return false;
            p.WaitForExit(4000);
            return p.ExitCode == 0;
        }
        catch { return false; }
    }

    public static async Task<bool> InstallAsync(string wingetId)
    {
        var args = $"install --id {wingetId} -e --silent --accept-package-agreements --accept-source-agreements";
        var psi = new ProcessStartInfo("winget", args) { UseShellExecute = true };   // may prompt UAC
        try
        {
            using var p = Process.Start(psi);
            if (p == null) return false;
            await p.WaitForExitAsync();
            return p.ExitCode == 0;
        }
        catch { return false; }
    }
}
