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

namespace Shared.Rcl.Commands.Servers.Gpus;

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

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

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

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