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

namespace Shared.Rcl.Commands.Systems;

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

        await useCase.ExecuteAsync(settings.Name);

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