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

namespace Shared.Rcl.Commands.Ups;

public class UpsNameSettings : CommandSettings {
    [CommandArgument(0, "<name>")] public string Name { get; set; } = default!;
}

public class UpsDeleteCommand(IServiceProvider provider)
    : AsyncCommand<UpsNameSettings> {
    protected override async Task<int> ExecuteAsync(
        CommandContext context,
        UpsNameSettings settings,
        CancellationToken cancellationToken) {
        using IServiceScope scope = provider.CreateScope();
        IDeleteResourceUseCase<RackPeek.Domain.Resources.UpsUnits.Ups> useCase = scope.ServiceProvider
            .GetRequiredService<IDeleteResourceUseCase<RackPeek.Domain.Resources.UpsUnits.Ups>>();

        await useCase.ExecuteAsync(settings.Name);

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