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

namespace ClaudeDo.Installer.Steps;

public sealed class CreateShortcutsStep : IInstallStep
{
    public string Name => "Create Shortcuts";

    public Task<StepResult> ExecuteAsync(InstallContext ctx, IProgress<string> progress, CancellationToken ct)
    {
        try
        {
            var appExe = Path.Combine(ctx.InstallDirectory, "app", "ClaudeDo.App.exe");
            var workingDir = Path.Combine(ctx.InstallDirectory, "app");

            // Start Menu shortcut
            var startMenuDir = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu),
                "Programs");
            Directory.CreateDirectory(startMenuDir);
            var startMenuPath = Path.Combine(startMenuDir, "ClaudeDo.lnk");
            ShortcutFactory.CreateShortcut(startMenuPath, appExe, workingDir, "ClaudeDo Task Manager");
            progress.Report($"Created Start Menu shortcut: {startMenuPath}");

            // Desktop shortcut (optional)
            if (ctx.CreateDesktopShortcut)
            {
                var desktopPath = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory),
                    "ClaudeDo.lnk");
                ShortcutFactory.CreateShortcut(desktopPath, appExe, workingDir, "ClaudeDo Task Manager");
                progress.Report($"Created Desktop shortcut: {desktopPath}");
            }

            return Task.FromResult(StepResult.Ok());
        }
        catch (Exception ex)
        {
            return Task.FromResult(StepResult.Fail(ex.Message));
        }
    }


}
