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

namespace Shared.Rcl.Commands.AccessPoints;

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

        await useCase.ExecuteAsync(settings.Name);

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