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

namespace Shared.Rcl.Commands.Services;

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

        await useCase.ExecuteAsync(settings.Name);

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