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

namespace Shared.Rcl.Commands.Routers.Ports;

public class RouterPortRemoveSettings : RouterNameSettings {
    [CommandOption("--index <INDEX>")] public int Index { get; set; }
}

public class RouterPortRemoveCommand(IServiceProvider sp)
    : AsyncCommand<RouterPortRemoveSettings> {
    protected override async Task<int> ExecuteAsync(CommandContext ctx, RouterPortRemoveSettings s, CancellationToken ct) {
        using IServiceScope scope = sp.CreateScope();
        IRemovePortUseCase<Router> useCase = scope.ServiceProvider.GetRequiredService<IRemovePortUseCase<Router>>();

        await useCase.ExecuteAsync(s.Name, s.Index);

        AnsiConsole.MarkupLine($"[green]Port {s.Index} removed from router '{s.Name}'.[/]");
        return 0;
    }
}
