using System.Diagnostics;
using System.IO;
using ClaudeDo.Installer.Core;

namespace ClaudeDo.Installer.Steps;

public sealed class StartWorkerStep : IInstallStep
{
    public string Name => "Start Worker";

    public Task<StepResult> ExecuteAsync(InstallContext ctx, IProgress<string> progress, CancellationToken ct)
    {
        var workerExe = Path.Combine(ctx.InstallDirectory, "worker", "ClaudeDo.Worker.exe");
        if (!File.Exists(workerExe))
            return Task.FromResult(StepResult.Fail($"Worker executable not found: {workerExe}"));

        progress.Report("Starting worker...");
        try
        {
            Process.Start(new ProcessStartInfo(workerExe) { UseShellExecute = true });
            return Task.FromResult(StepResult.Ok());
        }
        catch (Exception ex)
        {
            return Task.FromResult(StepResult.Fail($"Failed to start worker: {ex.Message}"));
        }
    }
}
