using Microsoft.Extensions.DependencyInjection;
using RackPeek.Domain.Resources.Desktops;
using RackPeek.Domain.UseCases;
using Spectre.Console;
using Spectre.Console.Cli;

namespace Shared.Rcl.Commands.Desktops;

public class DesktopDeleteCommand(IServiceProvider provider)
    : AsyncCommand<DesktopNameSettings> {
    protected override async Task<int> ExecuteAsync(
        CommandContext context,
        DesktopNameSettings settings,
        CancellationToken cancellationToken) {
        using IServiceScope scope = provider.CreateScope();
        IDeleteResourceUseCase<Desktop> useCase =
            scope.ServiceProvider.GetRequiredService<IDeleteResourceUseCase<Desktop>>();

        await useCase.ExecuteAsync(settings.Name);

        AnsiConsole.MarkupLine($"[green]Desktop '{settings.Name}' deleted.[/]");
        return 0;
    }
}
